Reputation: 192
What I'm trying to do:
I have some files in a directory, and I made a list of these:
filesInDir = os.listdir("scanfiles")
And after I got these, I'm trying to split the lines into seperate lists:
for files in filesInDir:
sourceFile = open("scanfiles/" + files, "r")
dynmicNameList = sourceFile.read().splitlines()
I would like it so that the array name is the file's name. So far I've only seen way more complicated scenarios for this problem. But I can't get this working.
Upvotes: 0
Views: 68
Reputation: 1122162
You want a dictionary for those lines, not local variables:
lines = {}
for files in filesInDir:
sourceFile = open("scanfiles/" + files, "r")
lines[files] = sourceFile.read().splitlines()
Upvotes: 3