Python sys.argv超出范围,不明白为什么 [英] Python sys.argv out of range, don't understand why
问题描述
我有一个脚本,我已经使用了一段时间,以轻松地上传文件到我的服务器。
代码很简单:
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,无效的文件路径)
exit()
filename = os.path.basename(filepath)
file_object = open (filepath,'rb')
ftp = FTP(主机)
ftp.login(acc,pw)
ftp.storbinary('STOR'+ filename,file_object)
ftp.quit()
file_object.close()
我运行它:
file_uploader.py backup.sql
我收到以下错误:
回溯(最近一次呼叫):
文件C:\Users\Admin\Desktop\file_uploader.py第12行在
filepath = sys。 argv [1]
IndexError:列表索引超出范围
我不知道为什么它给我一个错误,即使我传递一个脚本,它找不到第一个命令行参数。
我运行Windows 7 64 - 使用Python 2.7.2
感谢
py关联在注册表中不正确。结尾处缺少%*
。
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
I get the following error:
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\file_uploader.py", line 12, in
filepath = sys.argv[1]
IndexError: list index out of range
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
Thanks
Your .py association in the registry is incorrect. It's missing %*
at the end.
这篇关于Python sys.argv超出范围,不明白为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!