From: geremy condra on
On Wed, May 12, 2010 at 1:36 AM, Stefan Behnel <stefan_ml(a)behnel.de> wrote:
> Johan Förberg, 12.05.2010 10:05:
>>
>> On Tue, 11 May 2010 19:27:37 -0300, Gabriel Genellina wrote:
>>
>>> so open(False) is the same as open(0), and 0 is the file descriptor
>>> associated to standard input. The program isn't hung, it's just waiting
>>> for you to type some text
>>
>> That's interesting. Are there any more numbered pseudofiles? I suppose
>> its mainly an excellent way to confuse people when you open(0).read(),
>> but it would be interesting to know.
>
> Standard Unix behaviour dictates that 0 is stdin, 1 is stdout, and 2 is
> stderr. So you can only read() from 0.
>
> Stefan

Nitpicking, but open(1).read() and open(2).read() both succeed
(for small values of success) the same way that open(0).read()
does.

Thanks for the advice, everybody.

Geremy Condra
From: Giampaolo Rodolà on
2010/5/12 Gabriel Genellina <gagsl-py2(a)yahoo.com.ar>:
> open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
> builtin open() + os.fdopen() from 2.x all merged together. It does different
> things depending on the type and quantity of its arguments, and even returns
> objects of different types.
>
> In particular, open(some_integer) assumes some_integer is a file descriptor
> and return some variant of file object using the given file descriptor.

Interesting. I wasn't aware of this.
Is it documented somewhere?


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
From: Kushal Kumaran on
On Wed, May 12, 2010 at 10:56 PM, Giampaolo Rodolà <g.rodola(a)gmail.com> wrote:
> 2010/5/12 Gabriel Genellina <gagsl-py2(a)yahoo.com.ar>:
>> open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
>> builtin open() + os.fdopen() from 2.x all merged together. It does different
>> things depending on the type and quantity of its arguments, and even returns
>> objects of different types.
>>
>> In particular, open(some_integer) assumes some_integer is a file descriptor
>> and return some variant of file object using the given file descriptor.
>
> Interesting. I wasn't aware of this.
> Is it documented somewhere?
>

http://docs.python.org/py3k/library/functions.html#open

--
regards,
kushal
From: Terry Reedy on
On 5/12/2010 1:26 PM, Giampaolo Rodolà wrote:
> 2010/5/12 Gabriel Genellina<gagsl-py2(a)yahoo.com.ar>:
>> open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
>> builtin open() + os.fdopen() from 2.x all merged together. It does different
>> things depending on the type and quantity of its arguments, and even returns
>> objects of different types.

The change actually happened, according to 'What's new', in 2.6 when
'open' was made a synonym for the new io.open.

>> In particular, open(some_integer) assumes some_integer is a file descriptor
>> and return some variant of file object using the given file descriptor.
>
> Interesting. I wasn't aware of this.
> Is it documented somewhere?

Right where it should be, in the entry for 'open' under 'built-in
functions': "file is either ... or an integer file descriptor of the
file to be wrapped"


From: Dave Angel on


Giampaolo Rodol� wrote:
> 2010/5/12 Gabriel Genellina <gagsl-py2(a)yahoo.com.ar>:
>
>> open() in Python 3 does a lot of things; it's like a mix of codecs.open() +
>> builtin open() + os.fdopen() from 2.x all merged together. It does different
>> things depending on the type and quantity of its arguments, and even returns
>> objects of different types.
>>
>> In particular, open(some_integer) assumes some_integer is a file descriptor
>> and return some variant of file object using the given file descriptor.
>>
>
> Interesting. I wasn't aware of this.
> Is it documented somewhere?
>
>
>
http://docs.python.org/py3k/library/functions.html#open

.... or an integer file descriptor of the file to be wrapped.....


First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: default argument
Next: py2exe help