Probles parsing a text file
Miki Tebeka
miki.tebeka at zoran.com
Tue Jan 6 02:54:46 EST 2004
Hello,
> heres my text file(well the first two lines of it)
>
> #########################################
> # Default BMUS server CFG file #
...
> i heres the script that im using to parse the file
...
Try:
#!/usr/bin/env python
try:
fo = open("server.cfg")
print "Reading server CFG file"
for line in fo:
line = line.strip() # Strip white spaces
if (not line) or line.startswith("#"):
continue
eval(line) # *** UNSAFE ***
print "line executed"
except IOError, e:
print "Can't read server CFG (%s)" % e
Note that using "eval" is very unsafe. Someone might place
'shutil.rmtree("/")' inside the CFG file.
> many thnas for your help
No problem.
Miki
More information about the Python-list
mailing list