Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.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
windows上运行程序的python位置_Python_Command Line_Path - Fatal编程技术网

windows上运行程序的python位置

windows上运行程序的python位置,python,command-line,path,Python,Command Line,Path,我有一个python应用程序,需要知道它在运行时在哪个目录中创建 如何知道windows上正在运行的应用程序路径?例如,当我更改目录路径时,该路径已更改为新目录 有没有办法知道python应用程序在哪里运行,我们首先通过os.path.abspath(os.path.dirname(file)保存它 例如,用户需要知道应用程序在os.chdir(“c:/”)之后运行的位置 它包含在\u文件\u变量中 但是如果您想知道当前的工作目录,那么应该使用 编辑:有点晚!!!:) 编辑2:在C#中,你可以使

我有一个python应用程序,需要知道它在运行时在哪个目录中创建

如何知道windows上正在运行的应用程序路径?例如,当我更改目录路径时,该路径已更改为新目录

有没有办法知道python应用程序在哪里运行,我们首先通过os.path.abspath(os.path.dirname(file)保存它

例如,用户需要知道应用程序在os.chdir(“c:/”)之后运行的位置


它包含在
\u文件\u
变量中

但是如果您想知道当前的工作目录,那么应该使用

编辑:有点晚!!!:)
编辑2:在C#中,你可以使用属性AppDomain.CurrentDomain.BaseDirectory,因此使用类似的内容将有助于

Hi-SilentGhost的可能重复我更新了我的问题
     import os 
     print os.path.abspath(os.path.dirname(__file__))
     os.chdir("c:/")
     print os.path.abspath(os.path.dirname(__file__))
>>> os.getcwd()
'C:\\Program Files\\Python31'
>>> os.chdir(r'C:\\')
>>> os.getcwd()
'C:\\'
import os
print os.path.abspath(os.path.dirname(__file__))