Hi,
I have functions that take a file object and write to it. In some cases I
just want to throw out what is written to that file object. I want
something like open('/dev/null', 'w'), but portable.
It needs to have an underlying file descriptor/file handle, as it will be
passed to non python code.
Is there a portable /dev/null somewhere in the standard library?
Thanks,
Brendan 6 2566
On 2 Mag, 21:20, Brendan Miller <catph...@catphive.netwrote:
Hi,
I have functions that take a file object and write to it. In some cases I
just want to throw out what is written to that file object. I want
something like open('/dev/null', 'w'), but portable.
It needs to have an underlying file descriptor/file handle, as it will be
passed to non python code.
Is there a portable /dev/null somewhere in the standard library?
Thanks,
Brendan
I don't think so. You could define a dummy class emulating the file-
object API. Something like:
class NullDevice:
"A writeable object that writes to nowhere -- like /dev/null."
def write(self, s):
pass
closed = False
def close(self):
self.closed = True
--- Giampaolo http://code.google.com/p/pyftpdlib
Brendan Miller schrieb:
Hi,
I have functions that take a file object and write to it. In some cases I
just want to throw out what is written to that file object. I want
something like open('/dev/null', 'w'), but portable.
import os
null = open(os.devnull, "wb")
:)
Christian
Brendan Miller schrieb:
Hi,
I have functions that take a file object and write to it. In some cases I
just want to throw out what is written to that file object. I want
something like open('/dev/null', 'w'), but portable.
import os
null = open(os.devnull, "wb")
:)
Christian
I have functions that take a file object and write to it. In some cases I
just want to throw out what is written to that file object. I want
something like open('/dev/null', 'w'), but portable.
It needs to have an underlying file descriptor/file handle, as it will be
passed to non python code.
Is there a portable /dev/null somewhere in the standard library?
The subprocess module should work fine. Pass a pipe to the subprocess,
and read and discard anything from the pipe (e.g. in a separate thread).
If the non-Python code is inprocess, you are out of luck. Some systems
just don't support a null device, so Python can't possibly emulate it.
Regards,
Martin
En Fri, 02 May 2008 16:20:04 -0300, Brendan Miller <ca******@catphive.net>
escribió:
I have functions that take a file object and write to it. In some cases I
just want to throw out what is written to that file object. I want
something like open('/dev/null', 'w'), but portable.
It needs to have an underlying file descriptor/file handle, as it will be
passed to non python code.
Is there a portable /dev/null somewhere in the standard library?
pyimport os
pyprint os.devnull
nul
(this is on Windows)
--
Gabriel Genellina
On Fri, 02 May 2008 21:41:36 +0200, Christian Heimes wrote:
Brendan Miller schrieb:
>Hi,
I have functions that take a file object and write to it. In some cases I just want to throw out what is written to that file object. I want something like open('/dev/null', 'w'), but portable.
import os
null = open(os.devnull, "wb")
:)
Christian
Awesome. Thanks.
Brendan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nicolas Fleury |
last post by:
Hi everyone,
Is there an object in some standard library that would be the portable
equivalent of "file('/dev/null','w')" or do I have to create my own
class and object to do it? If it doesn't...
|
by: JKop |
last post by:
Would you classify the following code as "Undefined Behaviour" or as "Non-
portable"?
signed main()
{
signed char chedder = 130;
}
Relevant information:
|
by: aaronfude |
last post by:
Hi,
Perhaps this is slightly offtopic.
Coming into the Windows world from Unix.
Is there a reference on writing C++ libraries in a portable way.
For example, right now I'm sticking...
|
by: SenderX |
last post by:
I am porting a library from msvc++ to gcc and POSIX and was wondering if the
following was even close to being portable/c-std:
#define MEM_CAST unsigned char*
#define MEM_TO_OBJ( m, o...
|
by: Robert Bachmann |
last post by:
Two years I wrote a simple cesar encryption program, it worked but it
relied on ASCII.
So today I tried to make an portable cesar encryption.
Please tell me if the code below is really protable.
...
|
by: pemo |
last post by:
Is C really portable? And, apologies, but this is possibly a little OT?
In c.l.c we often see 'not portable' comments, but I wonder just how
portable C apps really are.
I don't write...
|
by: bwaichu |
last post by:
I have written the program below to just create and populate an html
file. I am running into a problem when viewing the created file in vi.
I am told by vi that the file does not have an end of...
|
by: Bart Van Loon |
last post by:
Hi all,
I'm looking for a portable (FreeBSD and Linux) way of getting typical
ifconfig information into Python.
Some research on the web brought me to Linux only solutions
...
|
by: upperclass |
last post by:
Hi,
I'm trying to find a decent way of measuring the running time of a
long-running program.
Say, the running time ranges from several seconds to more than a day.
The standard clock()...
|
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: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
| |