[Python-Dev] Rationale for NamedTemporaryFile? (original) (raw)
Aaron Bingham bingham at cenix-bioscience.com
Wed Mar 21 18:25:15 CET 2007
- Previous message: [Python-Dev] Rationale for NamedTemporaryFile?
- Next message: [Python-Dev] Rationale for NamedTemporaryFile?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Georg Brandl wrote:
Aaron Bingham schrieb:
Georg Brandl wrote:
Greg Ewing schrieb:
Scott Dial wrote: A tangential question -- why are TemporaryFile and NamedTemporaryFile named in TitleCase, when they're functions and not classes?
Probably because they are factory functions potentially returning a TemporaryFileWrapper. If they were "functions", they'd have to be verbed, e.g. "maketemporaryfile()". The class/function distinction is not so clear in Python from the user's point of view since there is no different calling syntax. Actually the distinction is very clear: >>> class PrivateClass(object): ... pass ... >>> def FunctionNamedToLookLikeClass(): ... return PrivateClass() ... >>> pc = PrivateClass() >>> isinstance(pc, PrivateClass) True >>> fntllc = FunctionNamedToLookLikeClass() >>> isinstance(fntllc, FunctionNamedToLookLikeClass) Traceback (most recent call last): File "", line 1, in TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types That's sure to be an unpleasant surprise for someone. duck typing... But you have a valid point. Sure, isinstance was only meant as an example. Anything that expects FunctionNamedToLookLikeClass to exhibit class-like behaviors beyond a call returning a new instance will fail.
-- Aaron Bingham Senior Software Engineer bingham at cenix-bioscience.com Tel. +49 (0)351 4173-146 Fax +49 (0)351 4173-109
Cenix BioScience GmbH Tatzberg 47 01307 Dresden, Germany www.cenix-bioscience.com
Sitz der Gesellschaft (Place of Business): Dresden Geschäftsführer (CEO): Dr. Christophe J. Echeverri Amtsgericht (Local Court): Dresden, HRB 19964 Ust-ID (VAT-No.): DE205824437
- Previous message: [Python-Dev] Rationale for NamedTemporaryFile?
- Next message: [Python-Dev] Rationale for NamedTemporaryFile?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]