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



On Mon, Jun 1, 2015 at 10:05 PM Sumant Shenoy <[email protected]>
wrote:

> thanks for your quick reply guys :) as i am preety new to classes i am not
> getting some stuff
> number 1 i only knew thre was some thing cld self and cls is a whole new
> thing i am guessing clss is short form for class and access class atributes
> i did change but i still got some errors
>
> example 1
> class test(object):
>     def __init__(self,x,y):
>         self.x=x
>         self.y=y
>     def info(cls):
>         print "%s,%s"%(self, self.x, self.y)
>
> ok=test("pSphere1","pSphere2")
> test().info()
>
> i got an error saying
>  __init__() takes exactly 3 arguments (1 given)
>
>
> example 2
>
> class test(object):
>     def __init__(self,x,y):
>         self.x=x
>         self.y=y
>     def info(self):
>          print "%s,%s"%(self, self.x, self.y)
>
> ok=test("pSphere1","pSphere2")
> ok.info()
> line 6: not all arguments converted during string formatting
>
>
> On Mon, Jun 1, 2015 at 6:45 PM, Rémi Deletrain <[email protected]>
> wrote:
>
>> oh yes I try after and I see my error... sorry...
>>
>> 2015-06-01 11:43 GMT+02:00 Justin Israel <[email protected]>:
>>
>>>
>>>  On Mon, 1 Jun 2015 9:41 PM Rémi Deletrain <[email protected]>
>>> wrote:
>>>
>>> try this
>>>
>>>
>>>
>>> class test(object):
>>>
>>>     def __init__(self,x,y):
>>>
>>>         self.x=x
>>>
>>>         self.y=y
>>>
>>>     def info(self):
>>>
>>>          print "%s,%s"%(self, self.x, self.y)
>>>
>>> ok=test("pSphere1","pSphere2")
>>>
>>>
>>>  test().info <http://test.info/>()
>>>
>>>  if you want call info with no instance add a decorator '@classmethod'
>>> and change 'self' by 'cls' before your function
>>>
>>> @classmethod
>>>
>>> def info(cls):
>>>
>>>     print "%s,%s"%(self, self.x, self.y)
>>>
>>>
>>>
>>>  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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/70f3e4b6-0b41-4c5d-820f-5899c6d2646e%40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/70f3e4b6-0b41-4c5d-820f-5899c6d2646e%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>>  --
>>> 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
>>> [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2RoPibZh9_sRVrxLmJn8LTK%3D9wmLsq3QeZHzJ%3DeY2RmQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2RoPibZh9_sRVrxLmJn8LTK%3D9wmLsq3QeZHzJ%3DeY2RmQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> *Rémi Deletrain.*
>> CG Artist, character TD.
>> *http://remideletrain.wix.com/remi-deletrain
>> <http://remideletrain.wix.com/remi-deletrain>*
>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/CACmfGpdmVP%3DESq9M8kWNatcc%3DqjY0duy9U%3DbEwaN3WxV3n9nOg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CACmfGpdmVP%3DESq9M8kWNatcc%3DqjY0duy9U%3DbEwaN3WxV3n9nOg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAGhqNnmCm6quqzhTgwXUSDx0VT7ayqYSgfz_Y3htv8JR0QXkbg%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAGhqNnmCm6quqzhTgwXUSDx0VT7ayqYSgfz_Y3htv8JR0QXkbg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2GSYioqJAVAcFyOsvPKym25wudpL%3Do%3D83LOnOZuf6gLA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to