1
我使用os.system调用(Python 2.7)以一种钝的方式自动执行一些繁琐的shell任务,主要是文件转换。然而,出于一些奇怪的原因,我的正在运行的解释器似乎无法找到我刚创建的文件。python:无法找到最近更改的目录(OSx)中的文件
示例代码:
import os, time, glob
# call a node script to template a word document
os.system('node wordcv.js')
# print the resulting document to pdf
os.system('launch -p gowdercv.docx')
# move to the directory that pdfwriter prints to
os.chdir('/users/shared/PDFwriter/pauliglot')
print glob.glob('*.pdf')
我期望有与所得的文件名的长度1列表,代替我得到一个空列表。
同样发生于
pdfs = [file for file in os.listdir('/users/shared/PDFwriter/pauliglot') if file.endswith(".pdf")]
print pdfs
我进行手动检查,以及预期的文件实际上是在那里,他们应该是。
此外,我的感觉是os.system被阻止,但为防万一它没有,我还在找到这些文件之前在那里插入了一个time.sleep(1)
。 (这足以让其他任务完成。)还没有。
嗯。帮帮我?谢谢!
哇,果然是那么简单。我现在觉得很愚蠢。 :-) 谢谢! –