python sys.argv_Python sys.argv超出范围,不明白为什么

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值