Использовать матрицу расстояний в scipy.cluster.hierarchy.linkage ()?

Возможно, вы ищете менеджер контекста ?

>>> class Foo(object):
...   def __init__(self):
...     self.bar = None
...   def __enter__(self):
...     if self.bar != 'open':
...       print 'opening the bar'
...       self.bar = 'open'
...   def __exit__(self, type_, value, traceback):
...     if self.bar != 'closed':
...       print 'closing the bar', type_, value, traceback
...       self.bar = 'close'
... 
>>> 
>>> with Foo() as f:
...     # oh no something crashes the program
...     sys.exit(0)
... 
opening the bar
closing the bar  0 

30
задан Sibbs Gambling 23 September 2013 в 06:38
поделиться