all Python 3until 3.12Removed from the standard libraryterm
configparser.SafeConfigParser
removed
Old name of the ConfigParser class for reading INI files. Removed in Python 3.12; use configparser.ConfigParser instead.
Syntax
configparser.SafeConfigParser() # до 3.12
Python 2 had three parsers: RawConfigParser, ConfigParser with unsafe interpolation, and SafeConfigParser with the fixed one. In Python 3.2 the "safe" behaviour became the plain ConfigParser and SafeConfigParser turned into an alias; it was deprecated and removed in 3.12. How to rewrite: configparser.SafeConfigParser() becomes configparser.ConfigParser(); the rest of the code (read(), get(), getint(), %(name)s interpolation) stays the same. While at it, replace readfp() with read_file(): it was removed in the same change.
Examples
# Python 3.12+
import configparser
try:
configparser.SafeConfigParser()
except AttributeError as e:
print(type(e).__name__) # → AttributeError
# Python 3.12+
import configparser
cp = configparser.ConfigParser()
cp.read_string('[db]\nhost = localhost\nurl = %(host)s:5432\n')
print(cp.get('db', 'url')) # → localhost:5432
import configparser
cp = configparser.SafeConfigParser()
cp.read_string('[db]\nport = 5432\n')
print(cp.getint('db', 'port')) # → 5432
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy