Python,我的Python cod中有一个意外的关键字参数

2024-05-17 11:35:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我的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'

我不明白我的函数有什么问题,或者我调用函数的方式有什么问题?


Tags: 代码indata错误levellistnestedchapter
1条回答
网友
1楼 · 发布于 2024-05-17 11:35:29

在上面的场景中,您可以使用其中一种。如果要进一步更改内容,则必须使用char数组,因为字符串在java中本质上是不可变的

相关问题 更多 >