2
A
回答
0
請參閱python文檔。 https://docs.python.org/2/library/configparser.html
import ConfigParser
config = ConfigParser.RawConfigParser()
config.add_section('Section')
config.set('Section', 'key1', '')
config.set('Section', 'key2', '')
config.set('Section', 'key3', '')
# Writing our configuration file to 'example.cfg'
with open('example.cfg', 'wb') as configfile:
config.write(configfile)
0
=
是格式的一部分,所以你不能告訴configparser忽略它。
但是你可以通過傳遞io.BytesIO()
對象來欺騙作者,並在寫入真實文件時剝離空格+等號。
自包含例如:
import ConfigParser,io
config = ConfigParser.RawConfigParser()
config.add_section('Section')
for i in range(1,4):
config.set('Section', 'key{}'.format(i), '')
# Writing our configuration file to 'example.cfg'
b = io.BytesIO()
config.write(b) # write in a fake file
# now write the modified contents to a real file
with open('output.ini', 'w') as f:
for l in b.getvalue().splitlines():
f.write(l.rstrip("= ")+"\n")
相關問題
- 1. 沒有分隔符的ConfigParser
- 2. ConfigParser VS SafeConfigParser在python 2.7
- 3. Python 2.7 ConfigParser中的ExtendedInterpolation()
- 4. Configparser設置沒有部分
- 5. configparser停止工作,ConfigParser正常!在Python 2.7
- 6. 分裂沒有分隔符
- 7. 沒有公共分隔符的Python字符串拆分
- 8. DecimalFormat沒有分組分隔符字符
- 9. Python - ConfigParser - AttributeError:ConfigParser實例沒有屬性'__getitem__'
- 10. 在Python 2.7中使用DOT作爲千分隔符
- 11. 在列表中沒有分隔符的多個分隔符處分割
- 12. 沒有捲曲到Python 2.7
- 13. 沒有分隔符的拆分命令
- 14. 拆分沒有分隔符的數據?
- 15. Python configparser特殊字符
- 16. Python CSV分隔符:分隔單元
- 17. 從ConfigParser進口SafeConfigParser導入錯誤:沒有模塊名爲「ConfigParser」
- 18. SQL Server 2012在分隔符前後找到文本,有時沒有分隔符
- 19. autoNumeric jQuery插件沒有分隔符
- 20. 字母從數字沒有分隔符
- 21. Android的ListView隨機沒有分隔符
- 22. 沒有分隔符的掃描器
- 23. PHP爆炸()沒有找到分隔符
- 24. 沒有分隔符的對話框
- 25. PregMatch沒有結束「)」分隔符發現
- 26. 沒有顯示Gtkada垂直分隔符
- 27. 沒有分隔符的array join()方法
- 28. 如何在沒有分隔符
- 29. 迭代在字符串中沒有空格作爲分隔符的分隔符
- 30. Python 2.7有沒有「忽略」功能?
它產生以下輸出'[部分] 鍵1 = 鍵2 = KEY3 = '反正有** = **從它剝離 – devel0pp3r