From: David S. <dsc...@vi...> - 2002-01-08 21:46:26
|
> def clickOn( self ): > print self.name ... > print "1" > print b.clickOn() > print "2" > When I ran this test script, I expected to get > "1\nBall 1\n2", but I got "1\nBall 1\nNone\n2". I have no > idea where "None" came from. When you call b.clickOn(), that function prints its name ("Ball 1"), but doesn't return anything. The print statement below then prints "None" which is what clickOn() returned. Change clickOn to be def clickOn( self ): return self.name and you will see what you expected. > Is there anybody who can help me with this problem? Is this > the right way of extending VPython? Any comment on any of > above questions will be greatly appreciated. The delegation approach you are using isn't a bad one for doing complicated things, but it isn't necessary merely to give objects names. VPython objects will accept any attributes you want, including name. The following complete program works fine: from visual import * A = sphere(name = "Ball A") print A.name Dave |