[Tutor] Using type

Christopher King g.nius.ck at gmail.com
Fri Aug 12 20:03:18 CEST 2011


>
>       try:
>          iter(item)  # test for iterability
>          if len(item) == 1 and item == item[0]:
>              gut.append(item)
>          else:
>              gut = gut + flatten(item)
>
>       except TypeError:
>          gut.append(item)
>
I wouldn't put the what you want to do if there is no error in the
try statement. It makes it appear like your checking for an error in all the
code. I would do.

      try:
         iter(item)  # test for iterability
      except TypeError:
         gut.append(item)
      else:
         if len(item) == 1 and item == item[0]: ##By the way, why do you
have this if statment
             gut.append(item)
         else:
             gut = gut + flatten(item)

Oh ya out of curiosity, what is the flatten func for?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110812/f342965e/attachment.html>


More information about the Tutor mailing list