Get my current path using a python script as a command

I put a python script to my /usr/local/bin to use as a command in bash.

I want to use my bash working directory, but I only get the current directory where the script is executed.

Is there a way to use the current directory as a command does? Eg with convert2ogg (as python script in /usr/local/bin)

$ cd ~/Music
$ convert2ogg *.mp3

import os,sys

print("CWD: "+os.getcwd())
print("Script: "+sys.argv[0])
print(".EXE: "+os.path.dirname(sys.executable))
print("Script dir: "+ os.path.realpath(os.path.dirname(sys.argv[0])))
pathname, scriptname = os.path.split(sys.argv[0])
print("Relative script dir: "+pathname)
print("Script dir: "+ os.path.abspath(pathname))

This code was very clear for me. os.path was not the solution for all my problems ;) I look for an answer, and seems anybody ask it before. The first line with os.getcwd() solved my problem.

链接地址: http://www.djcxy.com/p/54720.html

上一篇: cv2.imread在脚本中失败,而不是在命令行上

下一篇: 使用python脚本作为命令获取当前路径