|
Academic Work Personal
|
Python /
Preferences file
Contents of the [Options] color = "white" [Linux] tmp_dir = "/tmp" [Windows] tmp_dir = "c:/tmp"
import ConfigParser
import platform
# from the manwer project (http://code.google.com/p/manwer/)
def get_preferences(section, filename='preferences'):
#let's create a ConfigParser object
conf = ConfigParser.ConfigParser()
conf.read(filename)
val = {}
try:
val = dict((v, eval(k)) for v, k in conf.items(section))
except ConfigParser.NoSectionError:
val = {}
finally:
return val
##########
color = get_preferences('Options').get('color', 'black') # let it be 'black' if missing from the preferences
print color # white
tmp_dir = get_preferences(platform.system()).get('tmp_dir', None)
print tmp_dir # /tmp
|
![]() anime | bash | blogs | bsd | c/c++ | c64 | calc | comics | convert | cube | del.icio.us | digg | east | eBooks | egeszseg | elite | firefox | flash | fun | games | gimp | google | groovy | hardware | hit&run | howto | java | javascript | knife | lang | latex | liferay | linux | lovecraft | magyar | maths | movies | music | p2p | perl | pdf | photoshop | php | pmwiki | prog | python | radio | recept | rts | scala | scene | sci-fi | scripting | security | shell | space | súlyos | telephone | torrente | translate | ubuntu | vim | wallpapers | webutils | wikis | windows Blogs and Dev. * Ubuntu Incident Places Debrecen | France | Hungary | Montreal | Nancy Notes Hobby Projects * Jabba's Codes Quick Links [ edit ] |