syntax question - if 1:print 'a';else:print 'b'

Micah Elliott mde at micah.elliott.name
Thu Oct 27 13:41:39 EDT 2005


On Oct 27, Gregory Piñero wrote:
> 
>    my goal really was to do:
>    try:something(1);except:pass
>    try:something(2);except:pass
>    try:something(3);except:pass
>    ...
>    for about 20 lines.

If you just want to ignore the exceptions while saving space/typing,
you could equivalently do::

    try:
        something(1)
        something(2)
        # ...
    except:
        pass

or::

    try:
        something(1); something(2); # ...
    except:
        pass

or::

    try:
        for i in range(yourlimit):
            something(i)
    except:
        pass

-- 
_ _     ___
|V|icah |- lliott  http://micah.elliott.name  mde at micah.elliott.name
" "     """



More information about the Python-list mailing list