   Need suggestions for alternatives to pointers in Python
  I've been working off-and-on with Python for a while now, but just recently I decided to actually write something productive in it. I know a good portion of it's features but I still treat it as a 'slower C' rather than as it's own language.Now, since Python doesn't have pointers and I have come to a point (pun not intended, thankfully) where I would normally use pointers in C++. I'd like some suggestions of how to go about this without using pointers since I'm still stuck in C++-thinking.I have some lines segments that need to be dragged about the screen. So, when the mouse clicks on a point at either end of the line, that point is 'selected' and then moved about as the mouse moves. I need some method of remebering which one is currently 'selected'. In C++, I'd make a nice little pointer that would point to the currently selected point, and then set it's location to the mouse's location every frame. What are your suggestions as to handle this? Note that the points are actually 'inside' of a line class, so making a list of points and storing the index would be fairly complicated.Thanks in advanced.   
  It's good that you recognise being "stuck in C++ thinking". The hardest part for all of us is shedding the mental trappings of a previous language and learning to embrace whatever the new language has to offer.In Python, you can consider every variable to be much like a pointer. So, setting one variable to be 'equal' to a previous variable, actually makes them refer to the same object, just like if in C++ you had set a pointer variable to be equal to a previous pointer variable.So I'd say, add an object called self.selectedPoint into your line class. Set it to None by default. To select a point, do "self.selectedPoint = self.existingPoint", where existingPoint is whichever point you want. (You've not said exactly how you store them, so I can't advise on that.) Then you might want a member function called UpdateSelectedPoint(mouseX, mouseY), which simply does "self.selectedPoint = (mouseX, mouseY)", which will update whichever point you have currently selected. Check it isn't 'None' at the top of the function, or only call the function when it isn't 'None' (perhaps having an accessor method for that). To deselect the point, obviously you just do "self.selectedPoint = None".Any help?   ;  In Python, as in Java, object instances basically already *are* pointers (with all the referencing/dereferencing work inferred and done for you). Just that in Python, *everything* is an object and there are no primitive types (even numbers get the same treatment, whereas Java would distinguish between an int and a java.lang.Integer).Thus:>>> class Thingy:  def __init__(self, mystr):    self.mystr = mystr  def bar(self):    self.mystr += "bar"    >>> a = Thingy("foo")>>> b = a>>> b.bar()>>> a.mystr'foobar'>>> OK, so why doesn't this work if we just use a plain string?>>> a = "foo">>> b = a>>> b += "bar">>> a'foo'This is because in Python, '+=' isn't really a mutator: 'x += y' gets translated into 'x = x + y', which is the same (but sillier) with primitives, but has different implications when you're holding pointers-to-objects. The sum (or string concatenation) is being created as a new object, and then x is "rebound" to the new object. With the Thingy example, 'a' and 'b' refer to the same Thingy, so changes to the .mystr of one affect the other. But bar() actually *replaces* the .mystr rather than changing it.   ;  Woops, forgot about this thread after two days of inactivity. So, here goes a late "Thanks!" If I had only bothered reading these posts, I wouldn't have needed to spend alot of time wonder how my solution actually works (which surprised me quite a bit).So, I'm slightly confused about one thing. What if I wanted to make a copy of an object and not a handle or reference-like thing? Would I have to make a copy-constructor for the class in question?   ;Quote:Original post by EzbezSo, I'm slightly confused about one thing. What if I wanted to make a copy of an object and not a handle or reference-like thing? Would I have to make a copy-constructor for the class in question?I hope you wont think me rude for simply pointing to the documentation...docs.python.org/lib/module-copy.html