Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" """
__author__ = "Jens Diemer"
__url__ = "http://www.jensdiemer.de"
import sys, os, time, ConfigParser
class test:
def __init__(self):
start_time = time.time()
for i in xrange(10000):
self.get_ini_config()
print time.time() - start_time
start_time = time.time()
for i in xrange(10000):
self.get_py_config()
print time.time() - start_time
def get_ini_config(self):
f = file("config.ini", "rU")
config = ConfigParser.ConfigParser()
config.readfp(f)
f.close()
base_cfg = {
"bla1" : config.get("base", "bla1"),
"bla2" : config.get("base", "bla2")
}
dbconfig = {
"User" : config.get("dbconfig", "User"),
"Pass" : config.get("dbconfig", "Pass"),
"Server" : config.get("dbconfig", "Server"),
}
return base_cfg, dbconfig
def get_py_config(self):
import config
return config.base, config.dbconfig
#___________________________________________________________________________
if __name__ == '__main__':
test()
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
base = {
"bla1" : "suppe",
"bla2" : "blabla"
}
dbconfig = {
"User" : "UserName",
"Pass" : "Passowrd",
"Server" : "http://www.eifhei.com"
}
Code: Alles auswählen
[base]
bla1 = suppe
bla2 = blabla
[dbconfig]
User = UserName
Pass = Passowrd
Server = http://www.eifhei.com
Ausgabe:
Code: Alles auswählen
1.71900010109
0.0309998989105