I need to import this path variable from first class to another classes, this is my code:
import openpyxl
class Excell():
global path
def send_message(self, data):
global path
print("Path Excel is : '{}'".format(data))
path = data # I need to export this variable 'path'
global path
class First():
global path
wb = openpyxl.load_workbook(path)
sheet = wb['sheet']
firstCell= sheet["A1"].value
print("Cell is :" + firstCell)
After run code, I see this message:
C:\Python\python.exe E:/PycharmProjects/test/firstTest.py
Traceback (most recent call last):
File "E:\PycharmProjects\test\firstTest.py", line 11, in <module>
class First():
File "E:\PycharmProjects\test\firstTest.py", line 13, in First
wb = openpyxl.load_workbook(path)
NameError: name 'path' is not defined
Process finished with exit code 1