[Python-Dev] Rationale for NamedTemporaryFile?

Aaron Bingham bingham at cenix-bioscience.com
Wed Mar 21 14:03:00 CET 2007


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. "make_temporary_file()".
>
> 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 "<stdin>", line 1, in <module>
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.

-- 
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
---------------------------------------------------------




More information about the Python-Dev mailing list