Apr-11-2024, 07:17 AM
(Apr-10-2024, 03:01 PM)Gribouillis Wrote: [ -> ]I disapprove the solution that you found in stackoverflow because instead of solving the problem it hides the problem. You still don't know why the file name was not intercepted by the case statements. There is an error in the logic of your program and chose to conceal it instead of resolving it.Sorry, but I don't totally agree with you ;)
The solution I found on stack overflow just solves my problem about reading data from the audio file - and my bad, I didn't use the good function (used getvalue() instead of read() )
And in my context (just mine, I won't promise this script would be applicable everywhere), I know that I'll handle a limited number of file formats (didn't test with an iPhone, but with Android and Windows 10 I just need to handle m4a).
But I think for a larger program (or for a function which can be called by several other files) you would be right and it would be cleaner to add a
case _:
to throw an error if somebody tries to call convtomp3() with a csv, png or other non-foreseen case. ;)(Apr-10-2024, 03:01 PM)Gribouillis Wrote: [ -> ]For the temporary files, a good solution is to put them all in a temporary directory which is automatically destroyed at the end of a contextI'll try to add something like that, do you advice me to add this in the transcriptor function ?
>>> from tempfile import TemporaryDirectory, NamedTemporaryFile >>> >>> with TemporaryDirectory() as tdir: # create temporary directory ... print(tdir) ... with NamedTemporaryFile(dir=tdir) as f: # create temporary file inside temporary directory ... print(f.name) ... with NamedTemporaryFile(dir=tdir) as f: # same thing ... print(f.name) ... /tmp/tmpdhu6psra /tmp/tmpdhu6psra/tmp0b_i1wfp /tmp/tmpdhu6psra/tmpuvc0lsbc >>> >>> # all the files are gone now
Or is it possible to use
os.remove(temp_file.name)
after calling transcriptor at line 58?