【发布时间】:2021-07-08 04:55:28
【问题描述】:
我正在尝试打印以将endpoint 变量传递给RUN() 类中的__init__ 函数。但是它给了我一个错误。 AttributeError: module 'configs' has no attribute 'endpoint'。端点文档保存在file1.py 中,并在file2.py 中调用。我如何能够将端点作为参数传递。
文件1
endpoint = 'hello'
文件2
import file1
class RUN():
def __init__(self, endpoint= file1.endpoint):
print("Initialized")
run_websocket = RUN()
【问题讨论】:
-
您的代码对我来说很好用。文件是否在同一个文件夹中?
-
你能分享整个file1.py
-
最好创建一个名为 config 或 cfg 的模块以使该模块全局可用。
-
您是否有可能在代码中的某处使用
configs.endpoint或类似的东西?
标签: python function file class error-handling