繁体   English   中英

通过 class Python 传递变量

[英]Passing a variable through a class Python

我正在尝试打印以将endpoint变量传递给RUN() class 中的__init__ function。 但是它给了我一个错误。 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() 

代码绝对正确。 尝试删除 IDE 或 build 和 dist 文件夹等的缓存,然后再次运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM