【发布时间】:2016-07-15 07:58:08
【问题描述】:
我正在使用 os.system 调用(Python 2.7)以一种生硬的方式自动化一些乏味的 shell 任务,主要是文件转换。然而,出于某种奇怪的原因,我正在运行的解释器似乎无法找到我刚刚创建的文件。
示例代码:
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)。 (这对于完成其他任务来说已经绰绰有余了。)仍然没有。
嗯。帮助?谢谢!
【问题讨论】: