我该如何编写一个Python脚本,使其接受一个文件作为参数并打印出它的完整路径?
例如:
~/.bin/python$ ls
./ ../ fileFinder.py test.md
~/.bin/python$ py fileFinder.py test.md
/Users/theonlygusti/.bin/python/test.md
~/.bin/python$ py fileFinder.py /Users/theonlygusti/Documents/Online/theonlygusti.github.io/index.html
/Users/theonlygusti/Documents/Online/theonlygusti.github.io/index.html
那么,它应该找到相对文件 test.md
的绝对路径,以及通过绝对路径 /Users/theonlygusti/Downloads/example.txt
给出的文件的绝对路径。
我该如何创建像上面那样的脚本?
os.path.abspath
可以解决问题... - mgilson