Zameer wrote:
> I wonder where the "else" goes in try..except..finally...
>
try / except / else / finally
See the PEP:
http://www.python.org/dev/peps/pep-0341/
Kent
--
http://mail.python.org/mailman/listinfo/python-list
I wonder where the "else" goes in try..except..finally...
--
http://mail.python.org/mailman/listinfo/python-list
We used to have a try..except..finally syntax in Python. It was taken
out a while ago for reasons unknown to me. The good news is that it is
back in Python 2.5.
I haven't tested it, but Guido said so himself:
http://video.google.com/videoplay?docid=60331183357868340
--
http://mail.python.org/mai
> I tend to put "return"
> statements at the end of functions to make an attempt at being clean. I
> realize that a lot of the time functions will just return but I was
> hoping by explicitly stating my function returns that another person
> reading my code would more easily see any exit points in
Zameer wrote:
> That's it. But the return statement should not be a part of finally if
> you want exceptions to propagate out of the function containing
> try/finally. As mentioned multiple times in the thread.
>
Ah, great, that was it. Thanks to everyone for their help, I got a lot
of really
Doing cleaup in except is not the Python way. This is what finally is
for. Using except you would have to at least say:
try:
stuff()
cleanup()
except:
cleanup()
raise
Duplicate code - not nice. finally is the Python way:
try:
stuff()
finally:
cleanup()
That's it. But the
Carl J. Van Arsdall wrote:
(snip)
Not an answer to your question, just a few comments on your code:
> class Shared:
class Shared(object):
>def __init__(self):
>self.__userData= {}
>self.__mutex = threading.Lock() #lock object
Don't use __names unless yo
In article <[EMAIL PROTECTED]>,
"Maxim Sloyko" <[EMAIL PROTECTED]> wrote:
> I guess the following standard method will help :
>
> class MyLocker(object):
> def __init__(self, lock):
> self.lock = lock
> self.lock.acquire()
>
> def __del__(self):
> self.lock.r
Am Tue, 23 May 2006 12:47:05 -0700 schrieb Carl J. Van Arsdall:
> Hey python people,
>
> I'm interested in using the try/finally clause to ensure graceful
> cleanup regardless of how a block of code exits. However, I still am
> interested in capturing the exception.
You can reraise the except
"Carl J. Van Arsdall" <[EMAIL PROTECTED]> wrote:
> class Shared:
> def __init__(self):
> self.__userData= {}
> self.__mutex = threading.Lock() #lock object
>
> def getVar(self, variableName):
> temp = None
> error = 0
Unindent your first return statement. The return statement in putVar is
not needed.
--
http://mail.python.org/mailman/listinfo/python-list
I guess the following standard method will help :
class MyLocker(object):
def __init__(self, lock):
self.lock = lock
self.lock.acquire()
def __del__(self):
self.lock.release()
Then whenever you need to acquire a lock:
templock = MyLocker(self.__mutex)
del tem
12 matches
Mail list logo