[英]"No such file or directory" error when using "cat" in python
When I use当我使用
cat folder1/folder2/*_in.txt>>output.txt
directly in the terminal, it works fine.直接在终端中,它工作正常。
But when I call from inside the python process, it shows an error "No such file or directory"
:但是当我从 python 进程内部调用时,它显示一个错误
"No such file or directory"
:
command = "cat "+path+"*_in.txt >> " + output_variable
print(command) # print exactly the same.
os.system(command) # error : cat: folder1/folder2/*_in.txt: No such file or directory
This happens when there are no files matching the pattern:当没有与模式匹配的文件时会发生这种情况:
$ python -c 'import os; os.system("cat *.txt")'
cat: '*.txt': No such file or directory
$ echo 'Hello World' > myfile.txt
$ python -c 'import os; os.system("cat *.txt")'
Hello World
Be aware that files are matched relative to the process's current working directory ( os.getcwd()
), and not relative to the Python file.请注意,文件与进程的当前工作目录 (
os.getcwd()
) 相关,而不是与 Python 文件相关。 If you can't figure out the working directory and correct relative path to your files, use absolute paths.如果您无法确定工作目录和正确的文件相对路径,请使用绝对路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.