I’m a little confused on how the import system works in python…
So, I have a class in one file, and in one of the functions of the file, I have two variables, which I would like to import into another file.
LX = 1
LY = 2
I need to grab LY and LX from this file in order to import it into another…
Thanks alot, this is really my first time using separate files when using python, and also classes.
(If this wording doesn’t make sense please tell me, I’m trying to write better)
LX and LY seem to be local variables with the scope update() - which is a method of the Map class in your module, right?
Local variables cannot be exported/imported - otherwise, they would not be local .
For being able to tailor a “good practice” answer, I would need some further information, in particular why you need said LX / LY in other modules and in particular, if you really need a class attribute (and not an instance attribute) there?
But let me nevertheless already give you some idea - check out the following code:
LX = None
LY = None
Map.LX = 1
Map.LY = 1
from FileA import Map
mapp = Map()
Note, that I used Map.LX and not self.LX or LX ! We are talking about class attributes here…
Thanks Dominik I’ll try it