Problems with properties

wittempj@hotmail.com martin.witte at gmail.com
Fri Oct 14 11:53:14 EDT 2005


If you change it to this it works. You should provide a get and a set
function for a property.

class Task:
   def __init__(self, value):
     self._command = value

   def setCommand(self, value):
     self._command = value


   def getCommand(self):
     return self._command

   command=property(getCommand, setCommand)

class taskTest(TestCase):
     def testTask(self):
         t = Task("dir c:")
         c = t.command
         self.assertEquals("dir c:", c)

         # should fail, but doesn't
         t.command = "foo Bar"
         self.assertEquals("dir c:", t.command)


if __name__ == "__main__": 
     unittest.main()




More information about the Python-list mailing list