Hi,

I am really new in python programming and I want to build a class that perform 
various functions to the content(or lines) of any given file. I want to first 
include the opening and reading file function into that class, then add other 
methods.

Here is what I wrote for opening file and reading the lines:

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()
print allines

I define self.name variable because I want to store the specific file that I 
read. This works fine by the test code of print file1.filename. I saw 
"myfile.txt" on the terminal output.

However, the readAllline() method dose not work. The code only give me "None" 
as the output on terminal

What was wrong with this code? Thank for the help.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to