Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python等价于PHP';s______________________ _ _ _ _ _ _ _?_Php_Python_Magic Constants - Fatal编程技术网

Python等价于PHP';s______________________ _ _ _ _ _ _ _?

Python等价于PHP';s______________________ _ _ _ _ _ _ _?,php,python,magic-constants,Php,Python,Magic Constants,在PHP中,计算结果是指向包含该常量出现的文件的目录的路径 Python中是否有类似的功能 os.path.dirname(__file__) 在Python3.4及更新版本中,就是这样——您得到了一条绝对路径 在Python的早期版本中,是指在模块导入时相对于cwd的文件位置。如果调用chdir,信息将丢失。如果这成为一个问题,您可以将以下内容添加到模块的根目录中: import os.path _dir = os.path.dirname(os.path.abspath(__file__)

在PHP中,计算结果是指向包含该常量出现的文件的目录的路径

Python中是否有类似的功能

os.path.dirname(__file__)
在Python3.4及更新版本中,就是这样——您得到了一条绝对路径

在Python的早期版本中,是指在模块导入时相对于cwd的文件位置。如果调用
chdir
,信息将丢失。如果这成为一个问题,您可以将以下内容添加到模块的根目录中:

import os.path
_dir = os.path.dirname(os.path.abspath(__file__))

但是,同样,如果您只针对Python3.4+,这不再是必要的。

\uuuuu file\uuuuu
是绝对的,因为3.4 per,而且chdir似乎也不再是一个问题,正如有人可能想知道的那样,“为什么黑客不只是创建一个
\uuuu dir\uuuuu
?”。。。这是因为命名问题-python已经使用了
dir
\uuuu dir\uuuu()
但是对于对象属性获取。。。(别问我为什么)但我个人认为他们可能编造了一些类似《代码》的东西