Define a class containing methods for reading a file and then store lines in external variable
Chris Angelico
rosuav at gmail.com
Thu Aug 15 05:38:08 EDT 2013
On Thu, Aug 15, 2013 at 10:33 AM, Joug Raw <jougraw at gmail.com> wrote:
> class FileOpration:
> def __init__(self,name):
> self.name = name
> self.filename = self.name
> def readAllline(self):
> open(self.name).readlines()
>
> file1 = FileOpration("myfile.txt")
> print file1.filename
> allines = file1.readAllline()
You probably want to return that value:
def readAllline(self):
return open(self.name).readlines()
Then it'll do what you expect. But why wrap this up in a class? Why
not simply call the underlying functions directly?
ChrisA
More information about the Python-list
mailing list