i feel more general question, here example considering: have python class during initialization goes through zip archive , extracts data.
should code-chunk below written explicitly inside "def init" or should made method outside called inside "def init"? approach 'pythonic' one?
with zipfile(filename, "r") archive: item in archive.namelist(): match = self.pattern.match(item) if match: uid = match.group(2) time = match.group(3) else: raise badzipfile("bad archive")
if want execute statements showing in more 1 place, there's no discussion. without method or function task, violating dry principle.
otherwise... i'd write method regardless. task showing nicely self contained , should abstracted under descriptive name. make __init__
method easier maintain , easier read.
you should consider writing code showing module level function accepting pattern argument, because besides self.pattern
attribute task not seem have strong connection data , methods of class instances (from now).
Comments
Post a Comment