Python 子进程 cp 返回错误 - bufsize 必须是整数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34156193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Subprocess cp returns error - bufsize must be integer
提问by DanielHolden
I'm trying to copy from one directory to another, and rename them at the same time by calling 'cp' like so:
我试图从一个目录复制到另一个目录,并通过像这样调用 'cp' 同时重命名它们:
directories = ['/Users/Me/Folder1/File1.txt', '/Users/Me/Folder/File2.txt']
output = ['/Users/Me/Folder2/Hello.txt', 'Users/Me/Folder2/World.txt']
for in, out, in zip(directories, output):
subprocess.call('cp', in, out)
But it returns:
但它返回:
File "./test.py", line 33, in <module>
subprocess.call('cp', in, out)
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 659, in __init__
raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer
What am I doing wrong?
我究竟做错了什么?
采纳答案by Ayush
subprocess.call('cp', in, out)
in
is a python keyword. better use inp
as variable name. Also, subprocess.call()
expects a list
of arguments, not multiple arguments:
in
是一个python关键字。更好地inp
用作变量名。此外,subprocess.call()
需要一个list
参数,而不是多个参数:
for inp, out, in zip(directories, output):
subprocess.call(['cp', inp, out])