python - 路径 "."和 "./"以及 "./."之间的差异

标签 python linux terminal git-bash

我尝试了 ls '.'、ls './' 和 ls './.' ,它们都给了我相同的结果。

但是对于某个文件,我只能使用“python file ./”运行它,而不能使用其他两个选项。所以我想知道它们之间有什么区别。

编辑:

这不是我写的。

try:
    in_dir = sys.argv[1]
except:
    sys.exit("Usage: python formatter_oocl.py path/to/dir")

in_dir = "OOCL_RAW_DATA/" # name of directory where xls files will be read from
files = os.listdir("./"+in_dir)
#files = ['./' + in_dir + files[i] for i in range(len(files))]
print(files)

谢谢

最佳答案

. 是您当前的文件夹。后面的 / 仅指定它是一个文件夹,并允许您在后面指定其他文件夹/文件(例如 myfolder/myfile) 所以 ./.当前目录/当前目录

据我所知,没有区别...

./yourfile 执行您的文件(如果这是您所要求的)

关于python - 路径 "."和 "./"以及 "./."之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57382367/

相关文章:

linux - Make 不会重建使用 hg pull 更改的文件

linux:多线程,一个线程的 block 终端

linux - 重新加载 Linux 桌面而不重新启动或注销并重新登录?

linux - 诺基亚 N900 - Meego Linux - xterminal - shell 脚本 - 保持进程事件

Python the Hard Way - 练习 6 - %r 与 %s

java - 在 linux 中为 java 工具指定字体

python - 从父目录导入脚本

linux - Bash 脚本 : keep one line of local file in sync with remote file

python - 使用python重命名目录中的多个文件夹

python - alchemyapi-recipes-twitter - 无法正常工作