Python Forum
[Solved] I'm not getting the good type
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] I'm not getting the good type
#11
(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 context
>>> 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
I'll try to add something like that, do you advice me to add this in the transcriptor function ?
Or is it possible to use os.remove(temp_file.name) after calling transcriptor at line 58?
Reply


Messages In This Thread
[Solved] I'm not getting the good type - by slain - Apr-10-2024, 07:51 AM
RE: I'm not getting the good type - by Gribouillis - Apr-10-2024, 08:48 AM
RE: I'm not getting the good type - by slain - Apr-10-2024, 11:49 AM
RE: I'm not getting the good type - by Gribouillis - Apr-10-2024, 12:26 PM
RE: I'm not getting the good type - by slain - Apr-10-2024, 01:49 PM
RE: I'm not getting the good type - by Gribouillis - Apr-10-2024, 02:29 PM
RE: I'm not getting the good type - by slain - Apr-10-2024, 02:48 PM
RE: I'm not getting the good type - by Gribouillis - Apr-10-2024, 03:01 PM
RE: I'm not getting the good type - by slain - Apr-11-2024, 07:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] Good way to handle input args? Winfried 2 2,184 May-18-2021, 07:33 PM
Last Post: Winfried
  Type hinting - return type based on parameter micseydel 2 2,614 Jan-14-2020, 01:20 AM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020