This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2009年12月15日 19:29 by grego87, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| config.ini | grego87, 2009年12月15日 19:29 | config example | ||
| Messages (4) | |||
|---|---|---|---|
| msg96457 - (view) | Author: (grego87) | Date: 2009年12月15日 19:29 | |
If config.ini file is encoded with utf-8 with bom markers this code
import ConfigParser
config = ConfigParser.ConfigParser()
config.read("config.ini")
config.sections()
throws:
ConfigParser.MissingSectionHeaderError: File contains no section headers.
file: config.ini, line: 1
'\xef\xbb\xbf[section]\n'
ConfigParser should be able to read such files.
|
|||
| msg97335 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年01月07日 01:30 | |
Use utf_8_sig charset and open your file using io.open() or codecs.open() to get unicode sections, options and values.
Example:
-------------------------------------
from ConfigParser import ConfigParser
import io
# create an utf-8 .ini file with a BOM marker
with open('bla.ini', 'wb') as fp:
fp.write(u'[section]\ncl\xe9=value'.encode('utf_8_sig'))
# read the .ini file
config = ConfigParser()
with io.open('bla.ini', 'r', encoding='utf_8_sig') as fp:
config.readfp(fp)
# dump the config
for section in config.sections():
print "[", repr(section), "]"
for option in config.options(section):
value = config.get(section, option)
print "%r=%r" % (option, value)
-------------------------------------
|
|||
| msg111415 - (view) | Author: Łukasz Langa (lukasz.langa) * (Python committer) | Date: 2010年07月24日 02:09 | |
This is a sign of a broaded issue and should either be closed as invalid or superseeded by the main BOM issue. Brett, I would close it. |
|||
| msg111529 - (view) | Author: Mark Lawrence (BreamoreBoy) * | Date: 2010年07月25日 09:09 | |
Closing as the main BOM issue is addressed on #7651 and a solution to the OP's problem is given in msg97335. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:55 | admin | set | github: 51768 |
| 2010年09月24日 04:52:12 | AndrewZiem | set | nosy:
+ AndrewZiem |
| 2010年07月25日 09:09:02 | BreamoreBoy | set | status: open -> closed nosy: + BreamoreBoy messages: + msg111529 superseder: Python3: guess text file charset using the BOM resolution: duplicate |
| 2010年07月24日 02:09:41 | lukasz.langa | set | nosy:
+ brett.cannon, lukasz.langa messages: + msg111415 |
| 2010年01月07日 01:30:05 | vstinner | set | nosy:
+ vstinner messages: + msg97335 |
| 2009年12月26日 00:06:56 | benjamin.peterson | set | title: CompileParser can't read files with BOM markers -> ConfigParser can't read files with BOM markers |
| 2009年12月25日 07:41:54 | nirai | set | nosy:
+ nirai |
| 2009年12月15日 19:29:16 | grego87 | create | |