On Nov 6, 4:08 am, Dustan <[EMAIL PROTECTED]> wrote:
> On Nov 6, 3:58 am, Duncan Booth <[EMAIL PROTECTED]> wrote:
>
> > Wildemar Wildenburger <[EMAIL PROTECTED]> wrote:
> > > maybe something like this could help:
>
> > > def tupleize(non_tuple):
> > >      try:
> > >          return tuple(tupleize(thing) for thing in non_tuple)
> > >      except TypeError:
> > >          # non_tuple is not iterable
> > >          return non_tuple
>
> > Just don't try passing that a string or anything containing a string.
>
> Untested
>
> def tupleize(non_tuple):
>      if isinstance(non_tuple, str):
>           return non_tuple
>      try:
>           return tuple(tupleize(thing) for thing in non_tuple)
>      except TypeError:
>           # non_tuple is not iterable
>           return non_tuple


    isinstance(x,basestring)

is preferred over

    isinstance(x,str)

in case x is a unicode.

-- Paul

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to