Posted By

mouseroot on 02/15/11


Tagged


Versions (?)

Read and Parse key=value; config file


 / Published in: Python
 

this stores the key=value pairs in a dictionary called cvars perfect for config files as always comments/critisim welcomed!

  1. cvars = {}
  2.  
  3. def loadConfig(file):
  4.  
  5. configfile = open(file,'r')
  6. configlist = configfile.readlines()
  7. for x in configlist:
  8. if x[:1] == '[' or x[:1] == '/':
  9. pass
  10. else:
  11. vars = x.replace(';','').split('=')
  12.  
  13. cvars[vars[0]] = vars[1]

Report this snippet  

You need to login to post a comment.