繁体   English   中英

多行字符串EOF的Python subprocess.call

[英]Python subprocess.call with multiline string EOF

我遇到了一个我不太了解如何克服的问题。 我试图在python中创建一个子进程来运行另一个python脚本。 不太困难。 问题是当python文件包含超长字符串时,我无法解决EOF错误。

这是我的文件外观的示例。

Subprocess.py:

### call longstr.py from the primary pyfile
subprocess.call(['python longstr.py'], shell = True)

长篇

### called from subprocess.py
### the actual string is a lot longer; this is an example to illustrate how the string is formatted
lngstr = """here is a really long 
string (which has many n3w line$ and "characters")
that are causing the python file to state the file is ending early
"""
print lngstr

终端中的打印机错误

SyntaxError: EOF while scanning triple-quoted string literal

解决方法是,我尝试删除所有换行符和所有空格,以查看是否是因为它是多行。 那仍然返回相同的结果。

我的假设是,当子进程正在运行并且外壳正在对文件内容进行操作时,当到达新行时,外壳本身就吓坏了,这就是终止进程的原因。 不是文件。

子进程运行这样的文件的正确解决方法是什么?

谢谢您的帮助。

在这里回答我自己的问题; 我的问题是,我没有file.close()尝试执行之前subprocess.call

如果您遇到此问题,并且正在使用最近写入的文件,那么这也可能是您的问题。 感谢所有阅读或回复此主题的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM