0

Question about working with files (and help with my project)

I want to create a patient journal that creates patient files in a specific folder. I insert a name, if the folder contains a file named that, it allows me to make a new entry (I remember that Python likes to erase everything in a file when writing). If such a file isn't in a folder, it asks me if I want to create one. And it automatically adds a date and time. So how should I approach this? I want to use .txt files or something like that (I was once suggested .csv, just no).

11th Sep 2020, 5:47 AM
Ville Nordström
Ville Nordström - avatar
4 Antwoorden
+ 1
Bit by bit. First make a program that writes to a file, then make it so it'll check if the filename is already in the folder, then add some loops so you can do it multiple times. Just write a bit then test it over and over again until your satisfied. And if you want to write a file without deleting it, write in append mode.
11th Sep 2020, 5:58 AM
Slick
Slick - avatar
+ 1
use os module. # this will move you into directory os.chdir("home/example/directory") Theres should also be a file exists check somewhere, just do some research
11th Sep 2020, 6:14 AM
Slick
Slick - avatar
0
Thanks :) But how do I work with folders? That's my main question, sorry for leaving it unclear haha Like, how's the syntax that I need to use when asking the computer "is file x in folder y?"
11th Sep 2020, 6:02 AM
Ville Nordström
Ville Nordström - avatar
0
Thank you very much :)
11th Sep 2020, 6:17 AM
Ville Nordström
Ville Nordström - avatar