string bug/oddity?

Peter Hansen peter at engcorp.com
Sun Aug 12 22:49:12 EDT 2001


William Park wrote:
> 
> On Sun, Aug 12, 2001 at 07:45:15PM -0400, Peter Hansen wrote:
> > Anything wrong with this, simpler, approach?
> >
> > >>> for x in a.keys():
> > ...     print '%s%s' % (x, a[x])
> 
> This is better solution.  But, for educational purpose, in the original
> code, 'type()' returns special type values, not a regular string.  So,
> what your want is
>     type(a[x]) != type("")

Yes, obviously, of course, as both the responses preceding 
mine also clearly pointed out.

The original poster indicated he was new both to Python and
to programming, however, so it seemed very likely he believed
the complicated approach he was taking was necessary to 
get the behaviour he wanted.  Neither previous reply attempted 
to show him a better way, so I thought I might be adding
something of value by doing so (rather than just repeating
what the other two posts before mine had already said).

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list