-3
class Poc:

    var = 0

    def __init__(self):
        self.fileName = "input.txt"

    def readFile(self):
        with open('input.txt','r+') as fr:
            for line in fr:
                print line
                #enter code here

def main():
    obj=Poc()
    obj.readFile()

I was trying to pass arguments to the function and trying to read from the file. I cannot see anything happening after executing the code. I'm totally new to python please help.

I was trying to read from a file using the object.. please do share if anyone has links to learn python i couldn't find a good one.

danidee
  • 9,298
  • 2
  • 35
  • 55
sk79
  • 35
  • 10

1 Answers1

2

Your main function is never called. You could remove the function definition of main and just unindent

 obj = Poc()
 obj.readFile()

to module level. It is then executed every time that the module is called directly (using python yourscript.py) or when it's imported by another module.

If you don't want the latter behavior, you can wrap it in a if __name__=="__main__": condition, see here. For your simple case this should not be necessary though.

Community
  • 1
  • 1
jojonas
  • 1,634
  • 14
  • 24