Python的__file__实际上做了什么?

参见英文答案 > Is module __file__ attribute absolute or relative?4个
我一直认为__file__变量总是给你当前的文件名,但这似乎并不完全是它的作用.因为如果我认为这是真的,我一直面临着一个错误.

有人告诉我“__file__指的是最后搜索的模块”
这似乎更准确,但我想知道__file__应该做什么.

我找不到Python文档中提到的任何具体内容.
很多地方似乎都提到它,但不是很清楚.

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

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

解决方法

__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.

从这里:
http://mail.python.org/pipermail/python-dev/2010-February/097461.html

相关文章

我最近重新拾起了计算机视觉,借助Python的opencv还有face_r...
说到Pooling,相信学习过CNN的朋友们都不会感到陌生。Poolin...
记得大一学Python的时候,有一个题目是判断一个数是否是复数...
文章目录 3 直方图Histogramplot1. 基本直方图的绘制 Basic ...
文章目录 5 小提琴图Violinplot1. 基础小提琴图绘制 Basic v...
文章目录 4 核密度图Densityplot1. 基础核密度图绘制 Basic ...