Add flush() and close()#14
Add flush() and close()#14mgeier wants to merge 1 commit intobastibe:masterfrom mgeier:flush-and-close
Conversation
|
I implemented flush in 42dc599, just like you proposed. Thank you for the idea! |
|
I think that if we were to provide a I would find that behavior much worse than the current one. What do you think? As for |
|
Thanks for implementing A SoundFile zombie is indeed useless, but I think that's expected behavior. In Python itself it works the same way. Long story short, I think an An A context manager would be even better, but let's assume an interactive session here. If the The Regarding Citing http://docs.python.org/3.3/reference/datamodel.html:
and
Even if these should be extremely rare cases, it would be reason enough for me to provide a |
|
You finally convinced me. An Most of the arguments to
What do you think about this? |
|
Warning: following are my thoughts from thinking about these issues for just a short time, and without being intimate with the pysoundfile source code. I don't understand the problem with As to the second point, from what I can tell that would make sense. AIUI that would limit you to a handful of (common) formats (well, as many as you want, but at some point I expect it to get tedious ;) ), but I suspect that's OK for a higher-level interface that might be used by applications that don't care about all the niche formats that libsndfile supports (i.e., it would be the "stupid" interface to pysoundfile). Of course, you could again handle strings and |
|
I'm glad I could convince you! Now I guess the I don't think it's a good idea to give Regarding open mode: Regarding file formats: An example where all options are set by the user: Another example with more defaults ( I don't see the necessity for pre-defining tuples of @marcecj: I think |
|
I implemented some of the discussed points in #18. There is and I changed the open mode to I also changed the handling of file types as described above. The same thing can also be used with only positional arguments, if desired: The format can also be OR'ed together, if that's preferred: In most cases the file type can be obtained from the file extension, in this case And finally, if the default 16-bit samples are desired, it get's shorter once again: I would still regard this as the low-level interface because you still have to use the That's exactly the minimalism I'm after, in most cases I don't want to write more (but neither less, I wouldn't want a default value for The other named arguments work too, of course. And read is easy anyway: This reads the whole file by default, a part of a file can be read with the The only special case are Unlike I expected, I had a hard time finding default subtypes for most formats, because I really know only few of them. Missing mappings should be added (see the module-level dict |
|
I like this very much! Do you want to package these changes into a single pull-request? If not, I can just cherry-pick them from #18. |
|
I'm glad you like it! I'll have a look at #18 and will write a comment there which commits you could directly cherry-pick. The rest I will combine into one or more new commits. |
Now the integer mode constants are called READ, WRITE and RDWR. They are still in the module namespace, but now they have their own type _ModeType (derived from int). Alternatively, 'r'/'w'/'rw' and 'READ'/'WRITE'/'RDWR' (case-insensitive) can be used in the SoundFile constructor. This includes the strings suggested by @bastibe in #14. The strings 'r+'/'w+'/'a'/'a+'/... from the standard Python file objects are not used, because their behaviour is different from the modes in libsndfile which would lead to confusion. The mode is now the second constructor argument, right after the file name. This way, 'rw' can be used as positional parameter: f = SoundFile('myfile.wav', 'rw')
This is meant as a proof-of-concept implementation, there is definitely room for improvement.