all Python 3until 3.12Removed from the standard libraryfunction
configparser.RawConfigParser.readfp()
removed
Read INI settings from an open file object. Removed in Python 3.12; use read_file() instead.
Syntax
parser.readfp(fp, filename=None) # до 3.12
readfp(fp) took an open file (or any iterable of lines) and parsed it. Python 3.2 added read_file() for the same job under a clearer name, plus read_string() and read_dict(); readfp() was deprecated and removed from all parsers in 3.12. How to rewrite: cp.readfp(f) becomes cp.read_file(f); for text in memory use cp.read_string(text); for file paths use cp.read(['a.ini', 'b.ini']).
Examples
# Python 3.12+
import configparser, io
cp = configparser.ConfigParser()
try:
cp.readfp(io.StringIO('[s]\nk = v\n'))
except AttributeError as e:
print(type(e).__name__) # → AttributeError
# Python 3.12+
import configparser, io
cp = configparser.ConfigParser()
cp.read_file(io.StringIO('[s]\nk = v\n'))
print(cp['s']['k']) # → v
cp.read_string('[t]\nn = 3\n')
print(cp.sections()) # → ['s', 't']
import configparser, io
cp = configparser.ConfigParser()
cp.readfp(io.StringIO('[s]\nk = v\n'))
print(cp['s']['k']) # → v
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy