Python equivalent of #line?
Gerrit Holl
gerrit at nl.linux.org
Sun May 25 08:50:09 EDT 2003
Edward C. Jones schreef op zondag 25 mei om 14:27:34 +0000:
> C has a preprocessor command
> #line n "filename"
> Can I do this in Python?
Why do you want that?
You can get the current linenumber:
14:49:50:2:gerrit at stopcontact:/tmp$ cat test.py
#!/usr/bin/python
import sys
print sys._getframe().f_lineno; print sys._getframe().f_lineno
for i in xrange(3):
print sys._getframe().f_lineno
14:49:53:2:gerrit at stopcontact:/tmp$ python test.py
5
5
8
8
8
yours,
Gerrit.
--
203. If a free-born man strike the body of another free-born man or
equal rank, he shall pay one gold mina.
-- Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
http://www.sp.nl/
More information about the Python-list
mailing list