sys.stdout.write()

Fredrik Lundh fredrik at effbot.org
Tue Dec 19 11:36:47 EST 2000


Daniel Klein wrote:
> In 'Learning Python' by Mark Lutz and David Ascher, on page 77 it makes
> mention of the 'sys.stdout.write' method. However, when I check this out, I
> don't see the 'write' method in the list...
>
> >>> import sys
> >>> dir(sys.stdout)
> ['shell', 'softspace', 'tags']
>
> I must be doing something fundamentally wrong. :^(

dir() shows the contents of a given namespace.

For an instance object, this is the attributes defined in the
instance object, not anything defined by its class.

Instance objects provide a hidden attribute, __class__, which
points to the class object.

If the instance uses single-level inheritance, you can get away
with dir(sys.stdout.__class__).  To get the full inheritance tree,
you need to check the class object's __bases__ attribute as
well (recursively).

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list