It will. It will keep returning the same name and will overwrite that each time. You are asking for a file name which doesn't already exist on '/sd' which it correctly determines. You then write it to '/' not '/sd'. So, the next time it's called, the file won't be on '/sd' so it returns the same suggestion again.No error is getting displayed, but the file only gets saved in the raspberry pi pico itself and not in the SD Card. And the file also keeps overwriting on itself
Because the 'card.new_file()' returns the name of the new file, not its directory name. You need to use -
Code:
myfile = card.new_file(uos.listdir('/sd'))with open ('/sd/' + myfile, "w") as f:
Looking at that 'card.new_file' code I find it hard to believe whoever wrote that is an experienced Python or MicroPython programmer.
It can be simplified as below and could be written even better than this -
Code:
class card: def new_file(files): n = 0 while "chitti{}.csv".format(n) in files: n += 1 return "chitti{}.csv".format(n)
Statistics: Posted by hippy — Wed Jul 17, 2024 10:14 am