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'