Horje
config parser Code Example
python config file
''' config.cfg
[whatever]
key=qwerertyertywert2345
secret=sadfgwertgrtujdfgh
'''

from configparser import ConfigParser

config = ConfigParser()
config.read('config.cfg')

my_key = config['whatever']['key']
my_secret = config['whatever']['secret']
how to use config file to remove redundant variables in code
from ConfigParser import SafeConfigParser

parser = SafeConfigParser()
parser.read('simple.ini')

print parser.get('bug_tracker', 'url')
Source: pymotw.com
config parser
[DEFAULT]
ServerAliveInterval = 45
Compression = yes
CompressionLevel = 9
ForwardX11 = yes

[bitbucket.org]
User = hg

[topsecret.server.com]
Port = 50022
ForwardX11 = no
config parser #5
>>> topsecret.getboolean('ForwardX11')
False
>>> config['bitbucket.org'].getboolean('ForwardX11')
True
>>> config.getboolean('bitbucket.org', 'Compression')
True
config parser #4
>>> int(topsecret['Port'])
50022
>>> float(topsecret['CompressionLevel'])
9.0




Whatever

Related
can't resolve quill-image-drop-module Vue2Editor Code Example can't resolve quill-image-drop-module Vue2Editor Code Example
repeat macro x times vim Code Example repeat macro x times vim Code Example
two export in the same file Code Example two export in the same file Code Example
matlab covariance Code Example matlab covariance Code Example
bootstrap esp8266 web server Code Example bootstrap esp8266 web server Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7