python - Access to global variables when importing a custom class
问题描述
I have the following structure in my project:
myProject
|- classes
|- myclass.py
|- main.py
But myclass.py
doesn't see variables defined at main.py
main.py:
import pandas as pd
from classes.myclass import myclass
outputPath = '/some/path/'
classInst = myClass()
myclass.py:
import pandas as pd
class myClass:
def __init__(self):
global outputPath
self.outputPath = outputPath
dataFrame = pd.DataFrame(columns=['col1', 'col2'])
Is it possible to define global variables in outputPath
in main.py
only and use in that in all classes?
解决方案
推荐阅读
- python - 根据两个不同的列对一列求和
- python - 将 glumpy 小部件添加到 PyQt5 GUI
- sql - 检查文本列的数组是否包含包含短语的字符串
- r - 关于功能和生成输出和输入的硬件问题
- metal - 在 Metal 中,您可以在传递期间重用缓冲区参数表索引吗?
- python - Canny 边缘输出已损坏
- python-3.x - 谁能帮助我理解这个循环的逻辑?
- python - 如何提高 python/tesseract 图像到文本的准确性?
- data-cleaning - 数据清理,更新记录类别,基于 SQL Server 中的关键字(位于第二个表中)
- python - AttributeError:使用flask-sqlalchemy连接到sqlite数据库时无法设置属性