I'd like to share the global variable of another file in Python.

Asked 1 years ago, Updated 1 years ago, 91 views

I want to share and write global variables of other files like c++.

For example, path.The network paths required for the file py are

All specified in the global function

I want to take global variables from other Python files and use them as network paths.

Network paths are often changed or added, so I'd like to manage them from one file.

I can't find this way. If anyone knows how to do it, please help me.

python variable share global-variable

2022-09-22 21:09

1 Answers

"""
    path_file.py
"""

TEMP_HOST = '0.0.0.0'
TEMP_PORT = 8000

After you fill it out

"""
    another_file.py
"""
from yourpath.path_file import TEMP_HOST, TEMP_PORT

print(TEMP_HOST)

Can't we do it like this?

Or you can manage it with a class.

I manage both in the flask app.

Python-modules


2022-09-22 21:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.