From: Mark B. <mb...@0x...> - 2000-04-19 16:06:59
|
On Wed, 19 Apr 2000, Martijn Faassen wrote: > I think we shouldn't overload the load function too much. Can't we > instead have two functions, one to load from a file object, and another > to load through a filename? Or perhaps just don't have the last one > at at all; it's not hard to create a file object after all. Generally > it's better to have multiple functions instead of one function which > can receive an argument that can be fundamentally different types (such as > strings or file-like objects). The load function will remain the same, API wise. For languages like C++, function overloading using different types is common place. Though these are through seperate functions, in C++, the internal representation to the user of PySDL isn't overly important. > Loading from strings directly doesn't seem necessary to me either; you can > easily use StringIO or cStringIO to wrap the string up as a file-like > object after all? I agree. Polluting the API isn't worth the hassle, and its use is fairly limited. > From what I understood from the example, it seems 'file like' objects > are supported already, as I saw StringIO being used, right? In my implementation, file objects are supported. This is a direct type check in the module, so it doesn't support non-file objects with the same relative API. Eric Jacob's patch adds "file-like" object support, via inspecting the object passed to the various load functions, and determining if they have read/seek/etc methods; this is why StringIO works in his example. |