FW: Python equivalent of __LINE__ macro?

David Brady daves_spam_dodging_account at yahoo.com
Tue Jan 8 12:11:38 EST 2002


Thanks to all for the excellent answers.  It is as I
suspected; I'll have to try/except to catch errors. 
Oh well.

> I'm curious how __LINE__ would have solved your
> problem,
> though, if you were writing all this in C/C++.

The key is that, when you're running under DevStudio,
anything you print or send to stderr goes to the
output window.  If you output a message in the form of
"filename(linenumber): message", then DevStudio can
understand that.  If the developer hits F4, he'll be
taken to that file and line number.

In C/C++ it doesn't make AS much sense, since it isn't
parsed, but here's a thing I frequently do:

#define __STRINGIZE__(x) #x
#define __STR__(x) __STRINGIZE__(x)
#define _LOC_ __FILE__"("__STR__(__LINE__)") : "
#define TODO(x) message(_LOC_ "TODO: "#x) 

Now, if on line 42 of file ParrotSketch.cpp in
C:\Projects\Python, I type this line of text:

#pragma TODO("Lovely plumage, the Norwegian blue.")

Then when you build, you'll see this message in the
output:

C:\Projects\Python\ParrotSketch.cpp(42): TODO: Lovely
plumage, the Norwegian blue.

I also have a macro named WARN and one named ERR, and
DevStudio is clever enough that if it sees the word
"error" or "warning" go by in the output text, it will
increase the build error or warning count,
respectively.

As for Python, I was basically doing some stuff where
I just wanted to print something like "Hey, this bit
of script is buggy!" but I didn't want to hardcode the
line number, because I kept added code above it,
pushing it down the file.

Thanks again, all,

-dB

=====
David Brady
daves_spam_dodging_account at yahoo.com
I'm feeling very surreal today... or *AM* I?

__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/




More information about the Python-list mailing list