本文介绍了子进程cp返回错误-bufsize必须为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从一个目录复制到另一个目录,并通过调用'cp'来同时重命名它们,如下所示:
I'm trying to copy from one directory to another, and rename them at the same time by calling 'cp' like so:
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)
但它会返回:
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
我在做什么错了?
推荐答案
subprocess.call('cp', in, out)
$ 中的b
$ b
是python关键字。最好使用
inp
作为变量名。另外, subprocess.call()
期望参数的列表
,而不是多个参数:
in
is a python keyword. better use inp
as variable name. Also, subprocess.call()
expects a list
of arguments, not multiple arguments:
for inp, out, in zip(directories, output):
subprocess.call(['cp', inp, out])
这篇关于子进程cp返回错误-bufsize必须为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!