This is an exercise I wanted to try because I thought it was interesting. This exercise is unnecessarily complex for what it is doing, but it is trying to act as a practice to understand class, function and variable behavior in more complex dragon programs.
import os class grab file: fileObject = Def.__ fileObject = open (filename, "r") def getFile (): return self.fileObject class counter: fileC = any lineCount = 0 def __init __ (self, fileObject): self.fileC = FileObject def lineCounter (self): while true: self.fileC.readline () print (x) return linecarddef main (): fileGrabber = grabFile ("test.txt") FileObj = fileGrabber.getFile countObj = counter (fileObj) However, when I run it, I get the following error: traceback () (
Most recent call final): file "/ home / desk / desktop / tree / programming / Miscellaneous Project / TextN Alyzer.py ", line 32, & lt; Module & gt; In the main line, calculation = countObj.lineCounter () file "/ home / menu / desktop / tree / programming / file / home / menu / desktop / trii / programming / misscript projects / textonlazer" Miscellaneous Project / TextAnalyzer.py ", line 19, line quarters self.file C.Redline () attribute: There is no attribute 'readline' in the 'function' object [with exit code ending in 0.2 s] 1]
Does anyone show me this program Fully understand? Even more, though it is not the right place to ask, do any criticism on the style or formatting of the program? Especially "self" use
Thank you!
I think you call the method:
< Code> fileObj = fileGrabber.getFile ()
and you need to change the example method:
and your line The counter method requires some work:
def lineCounter (self): Self.lineCount = len (self.fileC.readlines ()) return yourself. Line
No comments:
Post a Comment