Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:print_lol()得到一个意外的关键字参数';fh&x27;_Python_Python 3.x - Fatal编程技术网

Python TypeError:print_lol()得到一个意外的关键字参数';fh&x27;

Python TypeError:print_lol()得到一个意外的关键字参数';fh&x27;,python,python-3.x,Python,Python 3.x,我有一个nester.py文件: """This is the "nester.py" module, and it provides one function called print_lol which print lists that may or maynot include nested lists""" import sys def print_lol(the_list, indent=False, level=0, fh=sys.stdout): """This fu

我有一个
nester.py
文件:

"""This is the "nester.py" module, and it provides one function called
 print_lol which print lists that may or maynot include nested lists"""
import sys 
def print_lol(the_list, indent=False, level=0, fh=sys.stdout): 
    """This function takes a positional argument called "the_list" which is
    any python list (of , possibly, nested lists). each data item in the provided
    list is (recursively) printed to the screen on its own line.
    A second argument called level is used to insert tab-stops when a nested
    list is encountered"""

    for each_item in the_list: 
        if isinstance(each_item, list):
            print_lol(each_item, indent, level+1, fh)

        else:
            if indent:
                for tab_stop in range(level):
                    print("\t", end = "", file=fh)


        print(each_item, file=fh
以及一些实际使用它的代码:

*************************************************************
# This is my actual code

import nester 

man = []
other = []

try:
    data = open("sketch.txt")
    for each_line in data:
        try:
            (role, line_spoken) = each_line.split(":", 1)
            line_spoken = line_spoken.strip()
            if role == "Man":
                man.append(line_spoken)
            elif role == "Other Man":
                other.append(line_spoken)

        except ValueError:
            pass
    data.close()
except IOError:
    print("The data file is missing!")

try:
    with open("man_data.txt", "w") as man_file:
        nester.print_lol(man, fh=man_file)


    with open("other_data.txt", "w") as other_file:
        nester.print_lol(other, fh=other_file)


except IOError as err:
    print("File error: " + str(err))
我在这个社区看到过一些帖子,但是没有一个能帮助我解决这个问题。我是Python新手,在过去的四天里,我一直处于这个阶段。我不知道如何使我的函数工作


我不知道是否需要安装其他软件包。如果不使用
nester
,程序即使不整洁也能正常工作。

什么是
帮助(nester.print\u lol)
输出?看起来您正在使用不同版本的方法。可能会检查您安装的库的版本与上述源代码的版本。shaara,您的编辑似乎破坏了实际代码,现在正在恢复。。。以及修改语法/布局:-)谢谢@Carcigenicate。这是有帮助的,因为有一些更新问题。