[Python-de] magischen Konstanten in Python?
Berthold Höllmann
berthold at despammed.com
Mo Jan 5 17:13:27 CET 2009
Mathias Uebel <mathias.uebel at meeloon.de>
writes:
> Hallo Freunde,
>
> in PHP gibt es die sogenannten "magischen Konstanten", wie __FILE__,
> __LINE__ etc. Ich habe das immer gern zum Debuggen genutzt. Gibt es so
> etwa auch in Python?
>
> Mathias
Normalerweise benutze ich
import inspect
def curPos(frame=1):
"""Print functionname, filename and line at called position.
"""
co = sys._getframe(frame).f_code
stack = inspect.stack()[frame]
return "%s (%s @ %d)" % (co.co_name, stack[1], stack[2])
und
print curPos()
als Ersatz for __FILE__ and __LINE__ debug print statements.
Berthold
--
__ Address:
G / \ L Germanischer Lloyd
phone: +49-40-36149-7374 -+----+- Vorsetzen 35 P.O.Box 111606
fax : +49-40-36149-7320 \__/ D-20459 Hamburg D-20416 Hamburg
-------------- nächster Teil --------------
Ein Dateianhang mit Binärdaten wurde abgetrennt...
Dateiname : nicht verfügbar
Dateityp : application/pgp-signature
Dateigröße : 193 bytes
Beschreibung: nicht verfügbar
URL : <http://mail.python.org/pipermail/python-de/attachments/20090105/65f3475f/attachment.pgp>
Mehr Informationen über die Mailingliste python-de