469,898 Members | 1,605 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

why uses tempfile.mktemp() "@" ?

Hi!

Is there a need for the "@"
in the filenames created with tempfile.mktemp()?

I think it would be better to use only characters
which are "shell save".

At least with bash you need to quote the "@".
Copy&past of the filename does not work.

Regards,
Thomas

Jul 18 '05 #1
3 2593
I'm not sure why "@" was chosen, but I've never had any problems with
it. I searched within the bash manual, and the only special meaning for
@ is when it is used as a variable name in a substitution ("$@"), as a
subscript in a substitution ("${name[@]}"), or when extglob is set, when
followed by an open-paren ("@(a|b|c)"). @ also has special meaning when
using tab-completion, but this shouldn't come into play.

You can probably change the behavior at runtime with something like
this:
import tempfile, os
def gettempprefix(): ... return "_%r-" % os.getpid()
... tempfile.gettempprefix = gettempprefix
tempfile.mktemp()

'/tmp/_21830-0'

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFAwKTiJd01MZaTXX0RAjr3AKCqGWSCTzvwhmZEGHXkoX pSMighagCeLBqy
59PNiNe1ieFAlI0IiXWekSQ=
=zOX7
-----END PGP SIGNATURE-----

Jul 18 '05 #2
Jeff Epler wrote:
I'm not sure why "@" was chosen, but I've never had any problems with


$ python2.2 -c"import tempfile;print tempfile.mktemp()"
/tmp/@3541.0
$ python2.3 -c"import tempfile;print tempfile.mktemp()"
/tmp/tmpLmdDeT

Whatever the reason was, it was changed in Python 2.3 anyway.

The following excerpt from the documentation may also be of interest for you
and the OP:

"""
mktemp(
[suffix][, prefix][, dir])

Deprecated since release 2.3. Use mkstemp() instead.
Return an absolute pathname of a file that did not exist at the time the
call is made. The prefix, suffix, and dir arguments are the same as for
mkstemp().

Warning: Use of this function may introduce a security hole in your program.
By the time you get around to doing anything with the file name it returns,
someone else may have beaten you to the punch.
"""

Peter

Jul 18 '05 #3
Am Fri, 04 Jun 2004 11:35:46 -0500 schrieb Jeff Epler:
I'm not sure why "@" was chosen, but I've never had any problems with
it. I searched within the bash manual, and the only special meaning for
@ is when it is used as a variable name in a substitution ("$@"), as a
subscript in a substitution ("${name[@]}"), or when extglob is set, when
followed by an open-paren ("@(a|b|c)"). @ also has special meaning when
using tab-completion, but this shouldn't come into play.


Hi Jeff,

Yes, "ls /tmp/@..." does work,
but if you create a temporary directory,
the tab-completion does not work.

Thank you for your reply,
Thomas

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by marco | last post: by
1 post views Thread by Matt Garman | last post: by
reply views Thread by Leo Breebaart | last post: by
5 posts views Thread by Gregory Piñero | last post: by
6 posts views Thread by James T. Dennis | last post: by
9 posts views Thread by billiejoex | last post: by
7 posts views Thread by byte8bits | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.