我的python代码一直给我这个错误。
这是我试图调用的函数,下面是调用它的代码。
from sys import stdout
def print_nested_list(lijst, indent=False, indent_level=0, fh=stdout):
for x in lijst:
if isinstance(x, list):
print_nested_list(x, indent, indent_level+1, fh)
else:
if indent:
for tabstop in range(indent_level):
print("\t", end='', file=fh)
print(x, file=fh)
try:
with open(r'C:\Python34\headfirstpython\chapter 3\man_data.txt', 'w') as man_data:
print_nested_list(man, fh=man_data)
with open(r'C:\Python34\headfirstpython\chapter 3\other_data.txt', 'w') as other_data:
print_nested_list(other, fh=other_data)
当我尝试运行它时,IDLE显示此错误
Traceback (most recent call last):
File "C:\Python34\headfirstpython\chapter 3\sketch1.py", line 25, in <module>
print_nested_list(man, fh=man_data)
TypeError: print_nested_list() got an unexpected keyword argument 'fh'
我不明白我的函数或者我调用函数的方式出了什么问题?
发布于 2014-05-08 00:53:36
在参数列表中,你没有'fh‘-你有'fh_id’。请尝试使用'fh‘。
发布于 2014-05-08 00:53:48
您的函数没有fh
关键字参数。不过,它有一个fh_id
关键字参数。
修复您的函数签名(将fh_id
重命名为fh
)或您的调用(使用fh_id
而不是fh
)。
https://stackoverflow.com/questions/23523747
复制相似问题