why uses tempfile.mktemp() "@" ?

  • Thread starter Thomas Guettler
  • Start date
T

Thomas Guettler

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
 
J

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.

You can probably change the behavior at runtime with something like
this:... return "_%r-" % os.getpid()
... '/tmp/_21830-0'

Jeff

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

iD8DBQFAwKTiJd01MZaTXX0RAjr3AKCqGWSCTzvwhmZEGHXkoXpSMighagCeLBqy
59PNiNe1ieFAlI0IiXWekSQ=
=zOX7
-----END PGP SIGNATURE-----
 
P

Peter Otten

Jeff said:
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
 
T

Thomas Guettler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,652
Latest member
Campbellamy

Latest Threads

Top