I have been trying to create a program that will allow the user to create a file where they will store their notes. I have managed to get this part down but now I have run into a problem with loading all the files as variables that the rest of the program can readily access. I have managed to find 2 ways to allow this to happen.
One is to call each file one at a time:
with open("file_name", "r") as working_notes:
file_name = json.load(working_notes)
... # and repeat for every file that needs to be opened.
as you could imaging this would become a bit to maintain and would require the code to be updated every time a new file was created. So great in the short term to just get the job done but really bad going forward.
The 2nd method was to use tuple packing/unpacking:
vzt_notes, rms_notes, nsr_notes, py_notes,\
vzt_keys, rms_keys, nsr_keys, py_keys, java_notes,\
java_keys= load_files(filenames)
# calls a function that opens all files related to each variable
This actually works and all I need to do is add a variable name to the tuple list and it works fine however this still requires me to edit the code each time a file is created. Its a lot more compact and partially automated with the call of the function but I need complete automation.
This is where I am getting stuck. after trying various loops I have written or trying to create the variables from a list (failed miserable) I can not seam to have all the files load when the program initiates as a variable name of the file name.
So my latest attempt has only gotten as far as being able to print out ever files content but I still am not sure how to take the filename of the file being opened and making it a variable with the same name as the file name so the rest of the program can see and work with said variable.
Here is what I tried last:
import os
path = 'C:/Users/mcdomi3/Documents/MINTworkspace/MINT/NotesKeys/'
for filename in os.listdir(path):
with open(path+filename, "r+") as filename:
filename = json.load(filename)
# print (filename)
as I said this last attempt has only gotten as far as to print the content of the files listed just to see if it is in fact doing something with the files. So I know I can read them at least during the for loop
.