I am writing a program to help me build matrixs for my pygame projects. (I am using tkinter for the setup window, then pygame to colour tiles to give them values between 0 and 9)
I was hoping that I could save projects with named files, to later be reopened. All I need is the values of the variables store in my .py save files. I've had no problem creating these save files, however I am struggling to load these files.
Currently I am using tkinters 'file dialog' to get the file address, then using the os module to get the filename from the address and assigning that to a variable.
The problem I am having is importing the information from a file when the filename could vary and is therefore stored in a variable.
Can anyone point me in the right direction to be able to import without having the filename when writing the code? TIA
Not my actual program, just put together the simplest example of the problem I'm trying to fix (File2 just contains "var = 1")
second_file = "file2.py"
from second_file import *
print(var)
Running this obviously gives me "ModuleNotFoundError: No module named 'second_file'" Just wondering if there is a way to rewrite this so it knows it's a variable?