从Linux调用python脚本会导致TypeError:file()最多需要3个参数(给定4个)
这个脚本已经运行了很多次(我是第一次使用它),所以我相信Linux中的命令是错误的,尽管我检查了很多次 该命令需要具有以下结构:从Linux调用python脚本会导致TypeError:file()最多需要3个参数(给定4个),python,linux,command-line-arguments,Python,Linux,Command Line Arguments,这个脚本已经运行了很多次(我是第一次使用它),所以我相信Linux中的命令是错误的,尽管我检查了很多次 该命令需要具有以下结构: python python_script_path.py -ccdb db_file.db -csvNameResolution input_csv_file.csv -csvManual another_input.csv -csvOut output_file.csv python脚本 # imports parser = argparse.ArgumentP
python python_script_path.py -ccdb db_file.db -csvNameResolution input_csv_file.csv -csvManual another_input.csv -csvOut output_file.csv
python脚本
# imports
parser = argparse.ArgumentParser(description='usage:')
parser.add_argument('-ccdb','--ccdb', help='input: file to read from',required=True)
parser.add_argument('-csvNameResolution','--csvNameResolution',help='input: csv file - the output of the name resolution script', required=True)
parser.add_argument('-csvManual','--csvManual',help='input: csv file - manually prepared', required=True)
parser.add_argument('-csvOut','--csvOut',help='output: csv file which is the merge of the 2 inputs plus data queried', required=True)
args = parser.parse_args()
myEncoding = 'utf-8'
sys.stdout = open(sys.stdout.fileno(), mode='w', encoding=myEncoding, buffering=1) # That's wehre the error occurs.
错误消息:
回溯(最近一次呼叫最后一次):
文件“python_script_path.py”,第39行,在
sys.stdout=open(sys.stdout.fileno(),mode='w',encoding=myEncoding,buffering=1)
TypeError:file()最多接受3个参数(给定4个)
我不明白这条消息有什么问题。我研究了类似错误消息的问题,但这个错误出现在各种不相关的场景中
谢谢 这段代码似乎是为Python 3编写的,但您正在使用Python 2调用它。在Python3中,open()的签名更改为包含各种其他参数,包括此脚本使用的
编码。尝试运行:
python3 python_script_path.py -ccdb db_file.db -csvNameResolution input_csv_file.csv -csvManual another_input.csv -csvOut output_file.csv
调用open()
毫无意义-第一个参数应该是文件名,但传递的是整数。这些参数看起来更像是用于os.fdopen()
。