我需要使用Python3讀取,編寫和創建一個INI文件。如何使用Python3讀寫INI文件?
FILE.INI
default_path = "/path/name/"
default_file = "file.txt"
Python的文件:
# read file and if not exists
ini = iniFile('FILE.INI')
# Get and Print Config Line "default_path"
getLine = ini.default_path
# Print (string)/path/name
print getLine
# Append new line and if exists edit this line
ini.append('default_path' , 'var/shared/')
ini.append('default_message' , 'Hey! help me!!')
UPDATE FILE.INI
default_path = "var/shared/"
default_file = "file.txt"
default_message = "Hey! help me!!"
http://docs.python.org/library/configparser.html? – 2012-01-16 17:57:30
其實,http://stackoverflow.com/a/3220891/716118怎麼樣? – voithos 2012-01-16 18:01:01