I am writing a class that reads the number of lines in a file before the line "end"
class readFile:
global count
global txt
def __init__(self):
self.count = 0
def open(self,file):
self.txt = open(file,"r")
def cnt(self):
str = txt.readline()
while str != "end":
self.count += 1
str = txt.readline()
def printline(self):
print "the number of lines = %d" % count
obj = readFile()
obj.open(raw_input("which file do you want to read? \n"))
obj.cnt()
obj.printline()
But when I run this bit of code i get the following error - NameError: global name 'txt' is not defined
I am shifting from java to python, so if there are any stylistic differences I apologize