python µÄ__FILE__,__LINE__¹¦ÄÜʵÏÖ
(2008-06-23 21:41)
·ÖÀࣺ Computer computer
ÔÚCÓïÑÔÀ__FILE__ºÍ__LINE__¸øµ÷ÊÔÌṩÁ˺ܴóµÄ·½±ã£¬½ñÍíÔÚдPYTHONµÄʱºòÏëµ½£¬PYTHONÊÇ·ñÓÐÀàËÆµÄ¹¦ÄÜʵÏÖÄØ£¿
GOOGLEÒ»·¬·¢ÏÖÁ½¸ö·½·¨£¬ÊÔÑéÒ»ÏÂÏÂÃæÕâ¾ä:
print "here is :",__file__,sys._getframe().f_lineno
ËüºÍCÖеÄÁ½¸öºêµÄ¹¦ÄÜÒ»ÑùÁË!
µ«¸ù¾ÝÕÒ¸öÍøÒ³http://nedbatchelder.com/blog/200410.html#e20041003T074926
sys._getframe().f_linenoËÆºõ²»ÊǺÜÊÜÍÆ¼öµÄ·½·¨¡£
ÒÔÏÂÕÒ¸öÍøÒ³ÌṩÁËʹÓÃinpectÄ£¿éµÄÁíÒ»ÖÖʵÏÖ·¢·¨
http://www.velocityreviews.com/forums/t363977-line-and-file-functionality-in-python.html
import inspect
try :
c=inspect.currentframe()
print c.f_code.co_filename£¬c.f_lineno,
finally :
del c


