首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Python,在我的python代码中有一个意外的关键字参数

Python,在我的python代码中有一个意外的关键字参数
EN

Stack Overflow用户
提问于 2014-05-08 00:51:42
回答 2查看 75.5K关注 0票数 0

我的python代码一直给我这个错误。

这是我试图调用的函数,下面是调用它的代码。

代码语言:javascript
运行
复制
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显示此错误

代码语言:javascript
运行
复制
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'

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

EN

回答 2

Stack Overflow用户

发布于 2014-05-08 00:53:36

在参数列表中,你没有'fh‘-你有'fh_id’。请尝试使用'fh‘。

票数 9
EN

Stack Overflow用户

发布于 2014-05-08 00:53:48

您的函数没有fh关键字参数。不过,它有一个fh_id关键字参数。

修复您的函数签名(将fh_id重命名为fh)或您的调用(使用fh_id而不是fh)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23523747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档