Re: File names and file objects [was Re: My Python annoyances]

2007-05-05 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote: ... > What do people think about functions that accept either a file name or a > file object? > > def handle_file(obj): > if type(obj) == str: > need_to_close = True > obj = file(obj, 'r') > else: > need_to_close = Fals

Re: File names and file objects [was Re: My Python annoyances]

2007-05-05 Thread Steven Howe
Steven D'Aprano wrote: On Fri, 04 May 2007 07:55:25 -0700, Alex Martelli wrote: What about the case where I have an array of objects that represent some particular binary file format. If the object is a file, then I want to copy its contents. If the object is a string, th

Re: Object interfaces and capabilities [was Re: File names and file objects [was Re: My Python annoyances]]

2007-05-05 Thread Paul Boddie
Steven D'Aprano wrote: > > What do people think about functions that accept either a file name or a > file object? > > > def handle_file(obj): > if type(obj) == str: > need_to_close = True > obj = file(obj, 'r') > else: > need_to_close = False > do_something_with