Point Object

Discussion in 'Python' started by pjmulla@googlemail.com, Jan 5, 2008.

  1. Guest

    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
     
    , Jan 5, 2008
    #1
    1. Advertising

  2. On Sat, 05 Jan 2008 03:37:33 -0800, 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/tut/tut.html

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

    Ciao,
    Marc 'BlackJack' Rintsch
     
    Marc 'BlackJack' Rintsch, Jan 5, 2008
    #2
    1. Advertising

  3. Soviut Guest

    On Jan 5, 6:37 am, "" <>
    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
     
    Soviut, Jan 6, 2008
    #3
  4. Guest

    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
     
    , Jan 6, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gopi

    point to point protocol

    Gopi, Jul 13, 2004, in forum: VHDL
    Replies:
    1
    Views:
    474
    Mike Treseler
    Jul 13, 2004
  2. H aka N
    Replies:
    15
    Views:
    15,665
    Ben Jones
    Mar 2, 2006
  3. Motaz Saad
    Replies:
    7
    Views:
    6,491
  4. USCode
    Replies:
    7
    Views:
    430
    jeffc
    Jul 9, 2004
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,337
    Saraswati lakki
    Jan 6, 2012
Loading...

Share This Page