Just good advice? = WAS("Re: getting system date")

Fredrik Lundh fredrik at pythonware.com
Sun May 11 17:24:35 EDT 2003


David Broadwell wrote:

> def zoobar(somelist):
>     ''' Takes a list an complains if it dosen't like it, might even give it
> back '''
>     if somelist:
>         if type(somelist) == type([]): # paranoia type tests ... bad coder,
> no biscut.
>             print "good list, put code here"
>             return somelist
>         else: print "zoobar requires list types not %s" % type(somelist)
>     else: print "zoobar need argument ... a list would be good."

that's usually spelled:

    def zoobar(somelist):
        assert isinstance(somelist, list)
        # ... list-using code goes here ...

if you need to run your code in versions older than 2.2, use:

    def zoobar(somelist):
        assert isinstance(somelist, type([]))
        # ... list-using code goes here ...

</F>








More information about the Python-list mailing list