python - Best way to handle ZeroDivisonError? -


i've got following code:

def chunk_trades(a):     last = a[0]     new = []     x in a.iteritems():         if np.abs((x[1]-last)/last) > 0.1:             new.append(x[1])             last = x[1]         else:             new.append(last)     s = pd.series(new, index=a.index)     return s 

sometimes last can zero. in case, i'd carry on gracefully if last zero.

what's cleanest way?

just replace line this:

if not last or np.abs((x[1]-last)/last) > 0.1: 

this not raise exception since left assertion checked first.


Comments

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -