[Tutor] I Give Up. - Follow up post

János Juhász janos.juhasz at VELUX.com
Wed Jul 5 14:07:00 CEST 2006


Dear Brian,

The best parser is python itself :)

let's make ports.py with your original content:
http = 80
https = 443
http1 = 81
smtp = 25
smtp2 = 587

In this case, you can import ports.py with simple 
>>> import ports
>>> ports.http
80
>>> 

You don't need to define a new file format, just use the python syntax and 
it will work.
The only problem is that the format has to follow the python systax.
So the next wont work
## Ports.py
http = 80
https = 443
http1 = 81
  smtp = 25
smtp2 = 587

>>> import ports
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "ports.py", line 5
    smtp = 25
    ^
SyntaxError: invalid syntax
>>> 

The same method can be used for making more complex ini files.
I like it very much.
It is because Python is a dynamic language.


Yours sincerely, 
______________________________
Janos Juhasz 



More information about the Tutor mailing list