[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Point Object

pjmulla@googlemail.com

1/5/2008 11:38:00 AM

I am nes to python and need some help. Can anyone lead me in the
right direction to create and print a Point object, and then use id to
print the object's unique identifier. Translate the hexadecimal form
into decimal and confirm that they match.

Any help woul be much appreciated.

Pete
3 Answers

Marc 'BlackJack' Rintsch

1/5/2008 11:48:00 AM

0

On Sat, 05 Jan 2008 03:37:33 -0800, pjmulla@googlemail.com wrote:

> I am nes to python and need some help. Can anyone lead me in the
> right direction to create and print a Point object, and then use id to
> print the object's unique identifier. Translate the hexadecimal form
> into decimal and confirm that they match.

The right direction would be the tutorial in the docs I guess:

http://docs.python.org/tu...

What do you mean by the "hexadecimal form"? `id()` returns ordinary
`int`\s and not strings.

Ciao,
Marc 'BlackJack' Rintsch

ian

1/6/2008 10:14:00 AM

0

On Jan 5, 6:37 am, "pjmu...@googlemail.com" <pjmu...@googlemail.com>
wrote:
> I am nes to python and need some help. Can anyone lead me in the
> right direction to create and print a Point object, and then use id to
> print the object's unique identifier. Translate the hexadecimal form
> into decimal and confirm that they match.
>
> Any help woul be much appreciated.
>
> Pete

You shouldn't have to compare the hex IDs. Just a simple comparison
operator will work:

firstPoint = Point()
secondPoint = Point()
print(firstPoint == secondPoint)

result: True

Bearophile

1/6/2008 6:04:00 PM

0

Pete:
> Translate the hexadecimal form
> into decimal and confirm that they match.

No need to convert the IDs...


Soviut:
> You shouldn't have to compare the hex IDs. Just a simple comparison
> operator will work:
>
> firstPoint = Point()
> secondPoint = Point()
> print(firstPoint == secondPoint)
>
> result: True

Remember about __eq__ and "is":

class Foo:
def __init__(self, x):
self.x = x
def __eq__(self, other):
return self.x == other.x

f1 = Foo(1)
f2 = Foo(2)
f3 = Foo(2)
f4 = f3
print f1 == f2, f1 is f2 # False False
print f2 == f3, f2 is f3 # True False
print f3 == f4, f3 is f4 # True True

Bye,
bearophile