Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: [SOLVED] Pointers in Python?

  1. #1
    Join Date
    Feb 2007
    Beans
    281

    Question [SOLVED] Pointers in Python?

    Recently I've been trying to learn Python using the documents at http://docs.python.org/ (which is what I should be using right?). Presently I'm trying to figure out how to make pointers (like can be found in C++)... or if they even exist in Python. I'd figure they do, but I'm having trouble figuring out how to make them. I suspect that its something thats either right under my nose (in the documentation) or something I've forgotten from the tutorial. I know I saw them mentioned once in the tutorial, but I cant see anything that appears to be related anywhere else on that page (or, probably due to my poor searching abilities, anywhere else in the documents). How could I make a pointer, or what would be my alternative?

  2. #2
    Join Date
    Aug 2006
    Location
    60°27'48"N 24°48'18"E
    Beans
    3,458

    Re: Pointers in Python?

    I don't understand what you need a pointer for? Everything is by reference in Python already.

    (No, they're not there unless in the C-interfacing stuff for specific reasons)
    LambdaGrok. | #ubuntu-programming on FreeNode

  3. #3
    Join Date
    Jun 2006
    Location
    CT, USA
    Beans
    5,267
    Distro
    Ubuntu 6.10 Edgy

    Re: Pointers in Python?

    IMHO you are trying to learn how to program C++ using Python syntax. Bad idea.

    Try to understand how Python is different from C++ (like references instead of pointers), and how to use native Pythonic approach to solve problems.

  4. #4
    Join Date
    Feb 2007
    Beans
    281

    Re: Pointers in Python?

    I don't understand what you need a pointer for?
    I'm trying to figure out how to store 3D model information. I figure it in my best interests to have the various polygon faces able to use the same vertecies rather than having duplicate vertex data. I would also like the vertecies to be able to refrence their 'master' bones without using duplicate data.

    I could sware I had some more difficult needs related to them, but nothing is occurring to me at the moment.

    IMHO you are trying to learn how to program C++ using Python syntax.
    Not exactly...
    Last edited by Zeotronic; August 20th, 2008 at 08:41 PM.

  5. #5
    Join Date
    Aug 2006
    Location
    60°27'48"N 24°48'18"E
    Beans
    3,458

    Re: Pointers in Python?

    Code:
    x = Vertex(0,0,0)
    y = x
    Now x and y point to same Vertex and thus share the vertex data...
    LambdaGrok. | #ubuntu-programming on FreeNode

  6. #6
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: Pointers in Python?

    In a C-ish way, let's say in Python everything is a pointer (passed by reference, is the technical term).

    To check if an object is the same as another (the same instance), use the 'is' operator, not '=='. ('is' is like comparing pointers and '==' like comparing the values of the dereferenced pointers).

    Yes, it was confusing for me too at the beginning... but it's nice.

  7. #7
    Join Date
    Jun 2006
    Location
    CT, USA
    Beans
    5,267
    Distro
    Ubuntu 6.10 Edgy

    Re: Pointers in Python?

    did you considered any 3D graphics module (which would be a wrapper to C library)?

    Disclaimer: I don;t do 3D graphics in Python but IIRC some people around do.

  8. #8
    Join Date
    Dec 2007
    Location
    .
    Beans
    Hidden!
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Pointers in Python?

    Quote Originally Posted by pmasiar View Post
    did you considered any 3D graphics module (which would be a wrapper to C library)?

    Disclaimer: I don;t do 3D graphics in Python but IIRC some people around do.
    +1.The Original Poster should use pyOpenGl.

  9. #9
    Join Date
    Feb 2007
    Beans
    281

    Re: Pointers in Python?

    Now x and y point to same Vertex and thus share the vertex data...
    I had considered that when you guys started questioning why I would need a pointer, but my test of it (and being that I'm not quite sure what your 'vertex' is this is hardly conclusive):
    Code:
    joust=9
    biscut=joust
    print joust
    print biscut
    joust=11
    print joust
    print biscut
    Yeilded...
    9
    9
    11
    9
    What was that supposed to be a class or something?
    ('is' is like comparing pointers and '==' like comparing the values of the dereferenced pointers)
    I had been confused as to the significance of 'is' being separate from '=='... I was wondering if thats what it was (at least after the start of this thread).
    did you considered any 3D graphics module (which would be a wrapper to C library)?
    I considered many of them, but ultimately decided against them. I would have went with python-OGRE, but it seems to me there were some problems with using it that I cant quite recall at the moment. Regardless I decided this was a great opportunity to learn.
    +1.The Original Poster should use pyOpenGl.
    I am using pyOpenGL... do you mean to say that unlike OpenGL, pyOpenGL has it's own means of storing 3D models with complicated bone/vertex interaction? I haven't really gotten to study pyOpenGL yet so I'm not sure what the differences or the Syntax is.

  10. #10
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: Pointers in Python?

    Expanding on CptPicard's post...

    The id function gives the "identity" of an object, which is effectively the object's memory address, so you can use it to verify what CptPicard said. For example:
    Code:
    >>> p = [1.0,2.5,3.8]
    >>> q = p
    >>> id(p)
    454904
    >>> id(q)
    454904
    p and q both refer to the same object. Assigning a new value to p changes the object to which p refers (but does not change the object to which q refers):
    Code:
    >>> p = [-1.0,-2.0,-4.0]
    >>> id(p)
    8195168
    >>> id(q)
    454904
    >>> q
    [1.0, 2.5, 3.7999999999999998]
    >>>
    By the way, I agree with the gist of the other posters comments: learn how Python variables work; don't try to recreate C/C++.
    Last edited by WW; August 20th, 2008 at 09:44 PM.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •