简体   繁体   中英

Passing a variable through a class Python

I am trying to print to pass the endpoint variable to the __init__ function within the RUN() class. However it is giving me an error. AttributeError: module 'configs' has no attribute 'endpoint' . The endpoint document is saved in the file1.py and it is called in file2.py . How would I be able to pass endpoint as a param.

file1

endpoint = 'hello'

file2

import file1
class  RUN():
    def __init__(self, endpoint= file1.endpoint):
    
        print("Initialized")

run_websocket = RUN() 

The code is absolutely correct. Try deleting the cache of your IDE or build and dist folders, etc. then run again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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