You almost have the whole thing correct, except for how you end up calling the method. A method is "bound" to a specific instance of a class.
# "ok", while not a very descriptive name, is now an instance of class "test"
ok = test("pSphere1", "pSphere2")
# call a method on your instance
ok.info()
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAGhqNnmE5FHP4xtxdF6rgrfSh4B7SFNNHsdmfOOdbYP_0d9%2BUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
class test(object):def __init__(self,x,y):self.x=xself.y=ydef info(self):print "%s,%s"%(self, self.x, self.y)ok=test("pSphere1","pSphere2")
This is an error. "self" is not defined. And if you switch it to "cls" it will still be an error because x and y are instance variables
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/70f3e4b6-0b41-4c5d-820f-5899c6d2646e%40googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/jVpv71o1tuk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2RoPibZh9_sRVrxLmJn8LTK%3D9wmLsq3QeZHzJ%3DeY2RmQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACmfGpdmVP%3DESq9M8kWNatcc%3DqjY0duy9U%3DbEwaN3WxV3n9nOg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAGhqNnmCm6quqzhTgwXUSDx0VT7ayqYSgfz_Y3htv8JR0QXkbg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2GSYioqJAVAcFyOsvPKym25wudpL%3Do%3D83LOnOZuf6gLA%40mail.gmail.com.
That worked perfectly :DThank you !!!
On Mon, Jun 1, 2015 at 7:17 PM, Justin Israel <justin...@gmail.com> wrote:I think you should disregard the suggestions about "cls" and classmethod. That suggestion, I don't feel, was properly taking into consideration your level of experience, and is only going to serve to confuse you until you get a bit more comfortable with basic class concepts.So, in the second example, you have one more error.def info(self):print "%s,%s" % (self, self.x, self.y)If you count the number of %s elements in your string, you have 2. But you are trying to pass 3 items to the formatting operation. Change it to this:def info(self):print "%s,%s,%s" % (self, self.x, self.y)That will pretend the string representation of your test class instance, the value of x, and the value of y
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAGhqNnnYTPqxkwo20%3DiWzO1j3Nu%3DNAe6KmXCGob3Bq%2Bo9gwkHw%40mail.gmail.com.