a list or not a list?

Alex Martelli aleax at aleax.it
Wed May 7 09:00:26 EDT 2003


Axel Grune wrote:

> Hi , I played around with the traceback module and I noticed something
> strange. When you execute this code
> 
> import traceback
> 
> class PseudoFile( object):
>    def write( self, data):

The data passed to the write method of any file-like object
is ALWAYS a string (or other object supporting the buffer
protocol, but, nobody does THAT...:-).

> but I expected something like this
> 
> <type 'list'>
> 4

Your expectation were unfounded.  The .write method is ALWAYS called
with a string argument.

> The output of print_exc does not seem to be a list or a tuple, so: what

To be precise: *the arguments which print_exc passes to the write method
of the filelike object it's given* most definitely AREN'T list or tuples.
They're strings, of course.

> is it? Another thing is that the write method seems to be excuted four
> times, once for every string.

Sure, why not?  Printing an exception is hardly a bottleneck operation
requiring optimization, so it will get coded however's most practical.


Alex





More information about the Python-list mailing list