[Tutor] Creating class / OOP structure
Johan Martinez
jmartiee at gmail.com
Wed Nov 6 00:55:05 CET 2013
I need help in modifying my program. Right now it looks as follows:
class Filedict():
def __init__(self, fname):
self.fname =fname
def parse(self):
with open(self.fname, 'r') as f:
....
# some file search and parsing logic
return parsed_file
def process(self, parsed_object):
for k in parsed_obj.keys():
....
return processed_file
I instantiate Filedict and use it as follows:
f = Filedict('sales.txt')
parsed_f = f.parse()
processed_f = f.process(parsed_f)
So I need to pass parsed_f again to the process method. I would like to use
process method directly on initialized object. For example:
f = Filedict('sales.txt')
f.process()
Can someone help me in improving my code?
Should I store parsed_file as an object attribute as follows?
class Filedict():
def __init__(self, fname):
self.fname =fname
self.parsed_file = self.parse()
Any help?
-Jm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131105/a86e20b4/attachment.html>
More information about the Tutor
mailing list