Getting around Python's referencing of variables

Member
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:

Code:
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
Apprentice
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
Member
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 4,822 Apr 1, 2010 05:07 PM
Last Post: NelsonMandella
  Weird problem passing integer variables.. quarus 6 4,796 Mar 15, 2009 12:47 PM
Last Post: quarus
  Newbie: Referencing Objects john42 4 3,521 Oct 26, 2008 11:18 AM
Last Post: Blacktiger
  Adding Member Variables to Classes FlamingHairball 2 3,196 Jan 12, 2008 02:43 PM
Last Post: FlamingHairball