TypeError: debug() missing 1 required positional argument: 'msg' when calling method from different class
本问题已经有最佳答案,请猛点这里访问。
请提出我做错了什么,我是新编码。
1。F.ST.PY文件:
1 2 3 4 5 6 7 8 9 | import logging class Log: def __init__(self,msg): self.msg = msg def debug(self,msg): FORMAT ="%(asctime)-15s%(message)s" logging.basicConfig(filemode ="w", filename="file.log", format = FORMAT, level=logging.DEBUG) logging.debug(self.msg) |
2。第二文件
1 2 | import first first.Log.debug("I am in debug mode") |
当我运行第二个.py文件时,我得到的错误是logging.log.debug("我处于调试模式")
1 | TypeError: debug() missing 1 required positional argument: 'msg'** |
我不确定您要做什么,但第一个问题是您需要使用提供的
在你的
此代码的工作方式之一是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 1. first.py file import logging class Log: def __init__(self,msg): self.msg = msg def debug(self): FORMAT ="%(asctime)-15s%(message)s" logging.basicConfig(filemode ="w", filename="file.log", format = FORMAT, level=logging.DEBUG) logging.debug(self.msg) 2. second.py file import first # Note that Log is initialized with the msg you want, and only then we call debug() first.Log("I am in debug mode").debug() |