Tôi cần đọc, viết và tạo một tệp INI bằng Python3.Cách đọc và ghi tệp INI bằng Python3?
FILE.INI
default_path = "/path/name/"
default_file = "file.txt"
Python File:
# 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!!')
CẬP NHẬT FILE.INI
default_path = "var/shared/"
default_file = "file.txt"
default_message = "Hey! help me!!"
Làm thế nào về http://docs.python.org/library/configparser.html? –
Thực tế, về http://stackoverflow.com/a/3220891/716118 thì sao? – voithos