Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for file handles in audio.signal.load_audio_file #220

Closed
flokadillo opened this issue Oct 6, 2016 · 1 comment
Closed

Check for file handles in audio.signal.load_audio_file #220

flokadillo opened this issue Oct 6, 2016 · 1 comment

Comments

@flokadillo
Copy link
Contributor

flokadillo commented Oct 6, 2016

audio.signal.load_audio_file(filename, ...) checks if the input is a filehandle using if not isinstance(filename, str). However, if filename is represented as type unicode, this condition is true as well and we therefore conclude that the variable is a file handle and try to close the file, which results in an error.
Therefore, I suggest it would be safer to check for file handles using
if hasattr(filename, 'read') or if isinstance(filename, file).

@superbock
Copy link
Collaborator

superbock commented Oct 10, 2016

You have to be careful, Python 3 does not have a unicode type, just str. Maybe just use try/except.

@superbock superbock changed the title Check for file handles in Signal.load_audio_file Check for file handles in audio.signal.load_audio_file Oct 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants