Getting Variables from a file

Peter Schneider-Kamp petersc at stud.ntnu.no
Sun May 28 03:31:10 CEST 2000


I would be careful about using this new string attributes.
After all not everyone has 1.6a2 installed.

import string

for line in string.split(vars,"\n"):
  try:
    k,v = string.split(line," = ")
    exec(line)
  except:
    # does not protect you from evil code
    # but may show some mistakes
    print "warning: not an assignment '"+line+"'"
    pass

emile at fenx.com wrote:
> 
> This should get you started:
>
> for line in vars.split("\n"):
>   try:
>     k,v = line.split(" = ")
>     exec (line)
>   except:
>     # doexn't parse out as tuple w/ interspersed =
>     pass
> 

--
Peter Schneider-Kamp          ++47-7388-7331
Herman Krags veg 51-11        mailto:peter at schneider-kamp.de
N-7050 Trondheim              http://schneider-kamp.de




More information about the Python-list mailing list