473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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 2826
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Pierre Rouleau | last post by:
Hi all! I am using Python 2.3.1 on Win32 (NT, 2000). Whenever a file imports the standard tempfile module, Python 2.3.1 issues the following warning: C:\Python23\lib\fcntl.py:7:...
2
by: marco | last post by:
Hello, I having a problem creating directories with Python 2.3.4 (compiled with gcc 3.2.2, under Linux 2.4.20-31.9). I'm writing a plugin which works in the following way: GUI --...
1
by: Matt Garman | last post by:
I've been working on a curses-based application in Python. My application effectively has a series of screens (or windows). When one screen closes, the previous screen should be exactly redrawin...
0
by: Leo Breebaart | last post by:
On MS Windows, I am trying to find out a good default location to save some temporary files. The tempfile module seemed to have exactly what I wanted: >>> import tempfile >>>...
6
by: Brendan | last post by:
Hi, I'm trying to mimic the IPC/messaging system of an specific OS in a portable way by using GCC's library. The IPC system uses buffered asynchronous messages, where any thread can send a...
5
by: Gregory Piñero | last post by:
Hey group, I have a command line tool that I want to be able to call from a Python script. The problem is that this tool only writes to a file. So my solution is to give the tool a temporary...
6
by: James T. Dennis | last post by:
Tonight I discovered something odd in the __doc__ for tempfile as shipped with Python 2.4.4 and 2.5: it says: This module also provides some data items to the user: TMP_MAX - maximum number...
9
by: billiejoex | last post by:
Hi there. I'm trying to generate a brand new file with a unique name by using tempfile.mkstemp(). In conjunction I used os.fdopen() to get a wrapper around file properties (write & read methods,...
7
by: byte8bits | last post by:
Wondering if someone would help me to better understand tempfile. I attempt to create a tempfile, write to it, read it, but it is not behaving as I expect. Any tips? <open file '<fdopen>', mode...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.