[Tutor] FW: class problem

Roelof Wobben rwobben at hotmail.com
Sat Sep 18 18:27:01 CEST 2010




Hello ,

Thanks everyone.

I solved it by this :


class Point:
   def __init__(self, x=0, y=0):
      self.x = x
      self.y = y


P=Point()
print P
print id(P)

and a calculator which can convert hex to decimal.

Roelof


> ----------------------------------------
>> From: steve at pearwood.info
>> To: tutor at python.org
>> Date: Sun, 19 Sep 2010 01:54:11 +1000
>> Subject: Re: [Tutor] class problem
>>
>> On Sat, 18 Sep 2010 07:14:03 pm Roelof Wobben wrote:
>>
>>> P=(Point)
>>
>> This line does not do what you think it does. Brackets in Python are
>> used for two things, grouping and calling functions.
>>
>> To call a function, or a class, you need to have the brackets *after*
>> the function:
>>
>> P = Point() # what about arguments to the function?
>>
>> If you surround it with brackets, as you do above, it does nothing. It's
>> like this:
>>
>> x = (1+1) # exactly the same as x = 1+1 without brackets
>>
>>
>>> a=0
>>> b=0
>>> a=id(P)
>>
>> It is a waste of time to initialise variables immediately before
>> initialising them again.
>>
>>
>>
>>> print a
>>> print b
>>> print P
>>>
>>> But now id is a decimal so I don't can't translate it.
>>
>> id(x) returns an integer. By default, integers always print in decimal,
>> if you want to print them in hex you can do this:
>>
>> hex(id(P))
>>
>>
>>
>> --
>> Steven D'Aprano
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor 		 	   		  


More information about the Tutor mailing list