Hi, c.l.p'ers-
I working on some code that creates a temporary file on Linux. I found some
code that the BDFL posted previously on the newsgroup and adapted it for my
use. I can't get the "pre-2.3" code to work.
try:
make_temp_file = tempfile.mkstemp # 2.3+
except AttributeError:
def make_temp_file( suffix='', prefix='', dir='', text=False ): #pre-2.3
path = tempfile.mktemp( suffix )
fd = os.open( path, os.O_WRONLY|os.O_CREAT|os.O_EXCL, 0700 )
os.unlink( path )
return ( os.fdopen( fd, 'w+b' ), path )
Here's the error:
File "utils.py", line 583, in make_temp_file
return ( os.fdopen( fd, 'w+b' ), path )
OSError: [Errno 22] Invalid argument
Anybody have any ideas on what I am doing wrong?
Thanks,
Don 2 2454
djw <do**********@hp.com> wrote: Hi, c.l.p'ers-
I working on some code that creates a temporary file on Linux. I found some code that the BDFL posted previously on the newsgroup and adapted it for my use. I can't get the "pre-2.3" code to work.
try: make_temp_file = tempfile.mkstemp # 2.3+ except AttributeError: def make_temp_file( suffix='', prefix='', dir='', text=False ): #pre-2.3 path = tempfile.mktemp( suffix ) fd = os.open( path, os.O_WRONLY|os.O_CREAT|os.O_EXCL, 0700 ) os.unlink( path ) return ( os.fdopen( fd, 'w+b' ), path ) Here's the error:
File "utils.py", line 583, in make_temp_file return ( os.fdopen( fd, 'w+b' ), path ) OSError: [Errno 22] Invalid argument
Anybody have any ideas on what I am doing wrong?
Replace the os.O_WRONLY with os.O_RDWR and all will be fine import tempfile, os suffix="" path = tempfile.mktemp( suffix ) fd = os.open( path, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700 ) f = os.fdopen( fd, 'w+b' ) f
<open file '<fdopen>', mode 'w+b' at 0xb7de7a60> print >>f, "Hello" f.seek(0) f.read()
'Hello\n' f.close()
--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Thank you very much, that was the ticket!
-Don
Nick Craig-Wood wrote: djw <do**********@hp.com> wrote: Hi, c.l.p'ers-
I working on some code that creates a temporary file on Linux. I found some code that the BDFL posted previously on the newsgroup and adapted it for my use. I can't get the "pre-2.3" code to work.
try: make_temp_file = tempfile.mkstemp # 2.3+ except AttributeError: def make_temp_file( suffix='', prefix='', dir='', text=False ): #pre-2.3 path = tempfile.mktemp( suffix ) fd = os.open( path, os.O_WRONLY|os.O_CREAT|os.O_EXCL, 0700 ) os.unlink( path ) return ( os.fdopen( fd, 'w+b' ), path ) Here's the error:
File "utils.py", line 583, in make_temp_file return ( os.fdopen( fd, 'w+b' ), path ) OSError: [Errno 22] Invalid argument
Anybody have any ideas on what I am doing wrong?
Replace the os.O_WRONLY with os.O_RDWR and all will be fine
import tempfile, os suffix="" path = tempfile.mktemp( suffix ) fd = os.open( path, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700 ) f = os.fdopen( fd, 'w+b' ) f <open file '<fdopen>', mode 'w+b' at 0xb7de7a60> print >>f, "Hello" f.seek(0) f.read() 'Hello\n' f.close()
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alan Illeman |
last post by:
How do I set several different properties for PRE in
a CSS stylesheet, rather than resorting to this:
<BODY>
<PRE STYLE="font-family:monospace;
font-size:0.95em;
width:40%;
border:red 2px...
|
by: Buck Turgidson |
last post by:
I want to have a css with 2 PRE styles, one bold with large font, and
another non-bold and smaller font.
I am new to CSS (and not exactly an expert in HTML, for that matter). Is
there a way to...
|
by: Jarno Suni not |
last post by:
It seems to be invalid in HTML 4.01, but valid in XHTML 1.0. Why is there the difference? Can that pose a problem when such a XHTML document is served as text/html?
|
by: Martin McCormick |
last post by:
I am obviously confused about how to write to the file created
by the mkstemp function.
The manual says that it returns a pointer to a file descripter
when successful and I think that the...
|
by: Rocky Moore |
last post by:
I have a web site called HintsAndTips.com. On this site people post tips
using a very simply webform with a multi line TextBox for inputing the tip
text. This text is encode to HTML so that no...
|
by: Eric Lindsay |
last post by:
I can't figure how to best display little snippets of shell script using
<pre>. I just got around to organising to bulk validate some of my web
pages, and one of the problems occurs with Bash...
|
by: Xah Lee |
last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully
Functional Notations
Xah Lee, 2006-03-15
Let me summarize: The LISP notation, is a functional notation, and is
not a...
|
by: Schraalhans Keukenmeester |
last post by:
I am building a default sheet for my linux-related pages.
Since many linux users still rely on/prefer viewing textmode and
unstyled content I try to stick to the correct html tags to pertain good...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |