0

I have this line here:

sys_status = status().read()

This should call the imported class/function:

class status(self):
 def read(self):
    with open("/home/pi/project/mytext.txt", "r+") as fo:
      fo.seek(0, 0)
      sys_status = fo.read(1)
    fo.closed
    return status

The result on the sys_status variable should be the readable text on the textfile, but instead when I call this:

sys_status = status().read()
print "Status:", sys_status

The result is: Status: keypaddweb.status

Whats wrong with my code?

Bobys
  • 677
  • 1
  • 14
  • 37
  • Note that the code in parenthesis after a class name is a list of the base classes that your class inherits from. Why are you inheriting from `self`? Is `self` the name of a base class? If so, it should be renamed to something more descriptive. Otherwise, you should be having your class inherit from `object` so that it is a [new-style class](http://stackoverflow.com/questions/54867/old-style-and-new-style-classes-in-python). –  Nov 07 '14 at 18:03

1 Answers1

1

I think you have an incorrect return statement in your read function - you mean to return sys_status and not return status, which will just print details about class status.

Also, your class definition is incorrect, either do

class status():
    def read(self):
    ...

or do

class status(object):
    def read(self):
    ...
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186