[英]Python sys.argv out of range, don't understand why
I have a script that I've been using for a some time to easily upload files to my server. 我有一个已经使用了一段时间的脚本,可以轻松地将文件上传到服务器。 It has been working great for a long time, but I can't get it to work on my new desktop computer. 长期以来,它一直运行良好,但是我无法在新的台式机上运行它。
The code is simple: 代码很简单:
import os.path
import sys
import os
from ftplib import FTP
host = ""
acc = ""
pw = ""
filepath = sys.argv[1]
if (not os.path.isfile(filepath)):
x = input("ERROR, invalid filepath")
exit()
filename = os.path.basename(filepath)
file_object = open(filepath, 'rb')
ftp = FTP(host)
ftp.login(acc, pw)
ftp.storbinary('STOR ' + filename, file_object)
ftp.quit()
file_object.close()
I run it as: 我将其运行为:
file_uploader.py backup.sql file_uploader.py backup.sql
I get the following error: 我收到以下错误:
Traceback (most recent call last): 追溯(最近一次通话):
File "C:\\Users\\Admin\\Desktop\\file_uploader.py", line 12, in 文件“ C:\\ Users \\ Admin \\ Desktop \\ file_uploader.py”,第12行,在
filepath = sys.argv[1] 文件路径= sys.argv [1]
IndexError: list index out of range IndexError:列表索引超出范围
I'm not sure why it's giving me an error that it can't find the first commandline argument even though I passed one to the script. 我不确定为什么会给我一个错误,即使我向脚本传递了一个参数也找不到第一个命令行参数。
I am running Windows 7 64-bit with Python 2.7.2 我正在使用Python 2.7.2运行Windows 7 64位
Thanks 谢谢
Your .py association in the registry is incorrect. 您在注册表中的.py关联不正确。 It's missing %*
at the end. 最后缺少%*
。
尝试:
\python27\python file_uploader.py backup.sql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.