Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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 通过路径上的命令确定调用方位置_Python_Shell_Path_Python 3.7 - Fatal编程技术网

Python 通过路径上的命令确定调用方位置

Python 通过路径上的命令确定调用方位置,python,shell,path,python-3.7,Python,Shell,Path,Python 3.7,如果我的系统上安装了python应用程序,该应用程序是否有办法确定从何处执行调用 例如,如果应用程序“myApp”安装在Users/myUsr/python/site packages,并且该应用程序是从/foo/bar/调用的,那么该应用程序能否确定调用者在文件系统上的位置 换言之: $ # pwd from different location $ pwd /foo/bar/ # call "myApp" which is installed at Users/myUs

如果我的系统上安装了python应用程序,该应用程序是否有办法确定从何处执行调用

例如,如果应用程序“myApp”安装在
Users/myUsr/python/site packages
,并且该应用程序是从
/foo/bar/
调用的,那么该应用程序能否确定调用者在文件系统上的位置

换言之:

$ # pwd from different location
$ pwd
/foo/bar/

# call "myApp" which is installed at Users/myUsr/python/site-packages
$ myApp -a input.file

也许这是显而易见的,但在运行过程中,必须将相对路径转换为绝对路径。

我认为
os.getcwd()
始终是程序运行时用户当前目录的绝对路径。您可能必须执行
os.path.abspath(os.getcwd())
,但我不这么认为(如果abspath没有CWD的abs路径,它将如何工作)。

我认为
os.getcwd()
在程序运行时始终是用户当前目录的绝对路径。您可能必须执行
os.path.abspath(os.getcwd())
,但我不这么认为(如果abspath没有CWD的abs路径,它将如何工作)。

它应该是
os.getcwd()
-执行程序时使用的目录。它应该是
os.getcwd()
-执行程序时使用的目录。