我有这样的subprocess
代码:
final_list = subprocess.Popen(['ls', destination], stdout=subprocess.PIPE).communicate()[0].splitlines()
这会将目录作为列表返回:
['genelaytics', '__init__.py', '__init__.pyc', 'settings.py', 'wsgi.pyc']
现在我想计算每个文件的大小并将文件作为单个元素连同大小和其他属性一起插入到数据库中。我尝试使用 for 循环:
for list in final_list:
st = os.stat(list)
size = st.st_size
b = File(file_name=list, source=test_url, start_date=start_date, end_date=end_date, size=size)
b.save()
运行上述代码时出现此错误:
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
20. return view_func(request, *args, **kwargs)
File "/home/zurelsoft/workspace/genelaytics/fileupload/views.py" in sync
94. st = os.stat(list)
Exception Type: OSError at /sync/
Exception Value: [Errno 2] No such file or directory: '__init__.py'