Thanks Roger!

I had written something fairly similar already.  I really wish there
was some validator decorator that would coerce the values into lists
for me.  Likewise, I wish the kwargs object was a special dictionary
that supported a "get_as_list" method.

IMHO, the python world should rethink making strings iterable.  I
would prefer that you had to cast a string into some "iterable string"
type before iterating across it.

I have been bitten more times than I can count by forgetting to check
the type of my object and then iterating across some string rather
than a list of strings.

Matt




On Feb 21, 2:09 pm, "Roger Demetrescu" <[EMAIL PROTECTED]>
wrote:
> On Thu, Feb 21, 2008 at 3:54 PM, Roger Demetrescu
>
> <[EMAIL PROTECTED]> wrote:
>
> >  def custom_ensure_sequence(obj):
> >     """Adapted from turbogears.util.ensure_sequence"""
> >     if obj is None:
> >         return []
> >     elif isSequenceType(obj) and not isinstance(obj, basestring):
> >         return obj
> >     else:
> >         return [obj]
>
> BTW, I believe this should be the correct implementation of TG's
> ensure_sequence function... IMHO, of course..  :)
>
> []s
> Roger
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to