I have a few hundred .txt files which I need to load and rather than type out variables for each of these I'd like way an automated process which will create a variable for each .txt file e.g.
Test.txt, Test1.txt and Test2.txt
give variables Test, Test1, Test2
I will then subsequently load each .txt file to the corresponding variable e.g.
Test = glob.glob('Test.txt')
Test1 = glob.glob('Test1.txt')
Test2 = glob.glob('Test2.txt')
I can create a list of all the file names and strip of the '.txt' motif e.g. ['Test', 'Test1', 'Test2']
but I'm unsure how (or even if its possible) to convert items in this list to variables.
I've tried reading around and seen that global()
or exec()
may be useful but I've never used them and seen plenty of people warning from using these so keen for more experienced input.
thanks in advance