[英]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.