Created
January 10, 2012 18:40
-
-
Save rennerocha/1590437 to your computer and use it in GitHub Desktop.
Manipulação de arquivos INI com Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[database] | |
host = localhost | |
dbname = example | |
port = 1234 | |
user = admin | |
password = secret | |
[repository] | |
type = git | |
url = [email protected]:user/project.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ConfigParser | |
config = ConfigParser.ConfigParser() | |
config.add_section('database') | |
config.set('database', 'host', 'localhost') | |
config.set('database', 'dbname', 'example') | |
config.set('database', 'port', '1234') | |
config.set('database', 'user', 'admin') | |
config.set('database', 'password', 'secret') | |
config.add_section('repository') | |
config.set('repository', 'type', 'git') | |
config.set('repository', 'url', '[email protected]:user/project.git') | |
with open('config.ini', 'w') as configfile: | |
config.write(configfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment