Why does this simple python program not work? -


class f:      'test'     def __init__(self, line, name, file, writef):     self.line = line     self.name = name     self.file = file  def scan(self):     open("logfile.log") search:         #ignore  part         line in search:         line = line.rstrip();  # remove '\n' @ end of line         if num == line:             self.writef = line  def write(self):     #this part not working     self.file = open('out.txt', 'w');     self.file.write('lines note:');     self.file.close;     print('hello world');  debug = f;  debug.write 

it executes no errors nothing, tried many ways, searched online 1 issue.

indentation part of python syntax, you'll need develop habbit of being consistent it. methods class methods, need indented such

anyway, here's modified version of script have ran, , works.

class f:     'test'     def __init__(self, line, name, file, writef):         self.line = line         self.name = name         self.file = file     def scan(self):         open("logfile.log") search:            #ignore  part             line in search:                 line = line.rstrip();  # remove '\n' @ end of line                 if num == line:                     self.writef = line     def write(self):         # should try , use 'with' open files, if         # hit error during part of execution,         # still close file         open('out.txt', 'w') file:             file.write('lines note:');         print('hello world'); # need call class constructor, not reference # class. (i've put dummy values in positional args) debug = f('aaa', 'foo', 'file', 'writef');  # same goes class method debug.write() 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -