[Python-de] os.read() verwirrt mich - TypeError: an integer is required

Kai Weber lists at glorybox.de
Mit Jan 28 22:21:29 CET 2004


>>> import popen2
>>> import os
>>> pipe = popen2.Popen4('cat file')
>>> pipe.fromchild
<open file '<fdopen>', mode 'r' at 0x401df860>
>>> data = os.read(pipe.fromchild, 80)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: an integer is required

Das verstehe ich nicht. Was läuft da verkehrt, denn zu os.read heißt es
in der Dokumentation[1]: 

    "... Note: this function is intended for low-level I/O and must be
    applied to a file descriptor as returned by open() or pipe(). To
    read a ``file object'' returned by the built-in function open() or
    by popen() or fdopen(), or sys.stdin, use its read() or readline()
    methods."

und das sind auch File-Objekte:

>>> file = open('file')
>>> file
>>> file
<open file 'file', mode 'r' at 0x401dfae0>

Kann mir jemand meinen Denkfehler erklären?

[1] http://www.python.org/doc/current/lib/os-fd-ops.html
-- 
  Kai Weber
» kai.weber at glorybox.de                     
  http://www.glorybox.de                GPG-Key: 0x594D4132