On Thu, 27 Nov 2008 12:12:38 +, adam carr wrote:
> I'm still in the position of having to right code to deal with
> converting None to an empty list and one object to a list with a single
> entry.
> Python casting doesn't work here.
Python doesn't have type-casting. Python has type conversion
"adam carr" <[EMAIL PROTECTED]> writes:
> Denis kindly provided the following code which does this well:
>
> def mkiter( x ):
>""" list -> list, el -> [el], None -> []
>usage: for x in mkiter( func returning list or
> singleton ): ...
>"""
>return (x if hasattr( x, "__iter__" )
On Nov 27, 8:57 am, Roy Smith <[EMAIL PROTECTED]> wrote:
> In article <[EMAIL PROTECTED]>,
> "adam carr" <[EMAIL PROTECTED]> wrote:
>
> > I call a function get_items() which returns a list of items.
> > However, in some cases, it returns just one item.
> > It returns the item as an object though,
In article <[EMAIL PROTECTED]>,
"adam carr" <[EMAIL PROTECTED]> wrote:
> I call a function get_items() which returns a list of items.
> However, in some cases, it returns just one item.
> It returns the item as an object though, not as a list containing one object.
> In other cases it simply retu
adam carr wrote:
2008/11/27 Stefan Behnel <[EMAIL PROTECTED]>:
adam carr wrote:
I call a function get_items() which returns a list of items.
However, in some cases, it returns just one item.
It returns the item as an object though, not as a list containing one object.
In other cases it simply r
Denis kindly provided the following code which does this well:
def mkiter( x ):
""" list -> list, el -> [el], None -> []
usage: for x in mkiter( func returning list or
singleton ): ...
"""
return (x if hasattr( x, "__iter__" ) # list tuple ...
else [] if x is None
el
2008/11/27 Stefan Behnel <[EMAIL PROTECTED]>:
> adam carr wrote:
>> I call a function get_items() which returns a list of items.
>> However, in some cases, it returns just one item.
>> It returns the item as an object though, not as a list containing one object.
>> In other cases it simply returns
adam carr wrote:
> I call a function get_items() which returns a list of items.
> However, in some cases, it returns just one item.
> It returns the item as an object though, not as a list containing one object.
> In other cases it simply returns None.
>
> What is the cleanest way to iterate over