[Python-Dev] Improved tmpfile module

Aahz aahz@pythoncraft.com
Fri, 28 Jun 2002 19:03:43 -0400

On Thu, Jun 27, 2002, Zack Weinberg wrote:
> This is largely as it was in the old file.  I happen to know that ~%s~
> is conventional for temporary files on Windows.  I changed 'tmp%s' to
> 'pyt%s' for Unix to make it consistent with Mac/RiscOS
> Ideally one would allow the calling application to control the prefix, but
> I'm not sure what the right interface is.  Maybe
>  tmpfile.mkstemp(prefix="", suffix="")
> where if one argument is provided it gets treated as the suffix, but
> if two are provided the prefix comes first, a la range()?  Is there a
> way to express that in the prototype?

The main problem with this is that range() doesn't support keyword
arguments, just positional ones.  In order to get the same effect with
mkstemp, you'd have to do

    def tmpfile.mkstemp(*args):

and raise an exception with more than two arguments.  Otherwise, if you
allow keyword arguments, you get the possibility of:


and you can't distinguish that from


unless you change the prototype to

    def tmp.mkstemp(*args, **kwargs):

which requires a bit more of a song-and-dance setup routine.

In any event, you probably should not use empty strings as the default
parameters; use None instead.

(Yeah, this is getting a bit off-topic for python-dev; I'm just
practicing for my book. ;-)
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/