Skip to content

Instantly share code, notes, and snippets.

@rennerocha
Created January 10, 2012 18:40
Show Gist options
  • Save rennerocha/1590437 to your computer and use it in GitHub Desktop.
Save rennerocha/1590437 to your computer and use it in GitHub Desktop.
Manipulação de arquivos INI com Python
[database]
host = localhost
dbname = example
port = 1234
user = admin
password = secret
[repository]
type = git
url = [email protected]:user/project.git
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