2013-07-02 24 views
5

Her zaman __file__ değişkeninin her zaman geçerli dosya adını verdiğini varsaydım, ancak bunun tam olarak ne yaptığı görünmüyor. Bunun doğru olduğunu varsayarsam bir hatayla karşılaştığımdan beri.Python'un __file__'si aslında ne yapıyor?

Birisi Ve bu daha doğru görünmektedir "arandı __file__ son birime değinen bir" söyledi, ama ben __file__ gerçekten yapmak gerekiyordu bilmek istiyorum.

Python belgelerinde belirtilen somut bir şey bulamadım. Çok fazla yer söz ediyor gibi görünüyor, ama bu konuda çok net değil. Buradan

http://docs.python.org/2/c-api/import.html?highlight=__file__

http://docs.python.org/2/c-api/module.html?highlight=__file__

+8

: http://stackoverflow.com/questions/7116889/python-file-attribute-absolute-or - göreceli –

+3

* Birisi bana şöyle dedi: "__file__' aranan son modüle atıfta bulunuyor" * Birisi yanlıştı, korkarım. –

+0

@MartijnPieters Ha, ben sadece '__file__' hakkında ne kadar belirsiz olduğumun bir örneği olarak kullanıyordum – ffledgling

cevap

3
__file__ is the pathname of the file from which the module was loaded, if it was loaded from a file. The __file__ attribute is not present 
for C modules that are statically linked into the interpreter; for 
extension modules loaded dynamically from a shared library, it is the 
pathname of the shared library file. 

: Bu yardımcı olabilecek http://mail.python.org/pipermail/python-dev/2010-February/097461.html