Getting around Python's referencing of variables

Posts: 100
Joined: 2006.05
Post: #1
I have a simple but very frustrating problem with Python. I know it should have a simple answer, but I'm just not familiar enough with Python to figure it out.

I need to do a 90 degree rotation of a velocity vector, but I'm having some trouble with the fact that Python, unlike C, treats assigned variables like pointers, rather than copies. My code is similar to this:

oldx = x
x = y
y = -oldx

The problem is that setting x = y also sets oldx = y, so I just get x = y and y = -y. Does anyone know how I can get a copy of a variable?
Quote this message in a reply
Posts: 13
Joined: 2006.10
Post: #2
Your code can be written like:
x,y = y,-x

But what type are x and y?
You can also take a look at copy module.
Quote this message in a reply
Posts: 100
Joined: 2006.05
Post: #3
Wow, I didn't even think of that. Thanks.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  exporting c functions and variables NelsonMandella 6 7,144 Apr 1, 2010 05:07 PM
Last Post: NelsonMandella
  Weird problem passing integer variables.. quarus 6 7,686 Mar 15, 2009 12:47 PM
Last Post: quarus
  Newbie: Referencing Objects john42 4 5,550 Oct 26, 2008 11:18 AM
Last Post: Blacktiger
  Adding Member Variables to Classes FlamingHairball 2 4,786 Jan 12, 2008 02:43 PM
Last Post: FlamingHairball