I have thousands of text files containing very long block of text(around 200kb - 600kb each file). I want to store contents of each file in a separate variable and to make it easier to identify it I want to store them in a variable that is the same as the file name. Suppose there is a text in the file 'dog.txt' I want to store it's content within a variable 'dog'.
Would it be possible? And if not, I could use a dictionary but can it hold that large amount? Or are there any alternatives?
PS: Please stop downvoting :P I realised my mistake.
The best you can do is use a dictionary. But you can also use "exec()" to create variables on the spot, though a dictionary is the right tool for it. Supposing all your files don't start with a number nor contain any invalid characters for a variable name:
import os
fileNames = os.listdir(os.path.join(os.getcwd(), 'subfoldername'))
for fName in fileNames:
f = open(fName, 'r')
exec("{0} = '{1}'".join(fName.split('.')[0]), f.read())
f.close()
print(dog) #prints out content of the file "dog.txt"