473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

python references

>>from Numeric import zeros
>>p=zeros(3)
p
array([0,0,0])
>>p[0]
0
>>x=p[0]
x=10
p
array([0,0,0]) #actual behavior
#array([10,0,0]) #desired behavior

I want x to be a C++-esque reference to p[0] for convenience in a
vector3 class. i dont want accessor methods. i know python can do
this, but it's been a long time since I used it and am unsuccessful in
my googling and docreading. a little help please?

Feb 5 '07 #1
2 1163
du*********@gmail.com wrote:
>>>from Numeric import zeros
p=zeros(3)
p
array([0,0,0])
>>>p[0]
0
>>>x=p[0]
x=10
p
array([0,0,0]) #actual behavior
#array([10,0,0]) #desired behavior

I want x to be a C++-esque reference to p[0] for convenience in a
vector3 class. i dont want accessor methods. i know python can do
this, but it's been a long time since I used it and am unsuccessful in
my googling and docreading. a little help please?
Nope, python can't do this.

Diez
Feb 5 '07 #2

du*********@gmail.com wrote:
>from Numeric import zeros
p=zeros(3)
p
array([0,0,0])
>p[0]
0
>x=p[0]
`x' is now a reference to immutable integer object
with value 0, not to first element of array `p'
>x=10
now `x' is a reference to immutable integer object
with value 10, array doesn't change
>p
array([0,0,0]) #actual behavior
#array([10,0,0]) #desired behavior

I want x to be a C++-esque reference to p[0] for convenience in a
vector3 class. i dont want accessor methods. i know python can do
this, but it's been a long time since I used it and am unsuccessful in
my googling and docreading. a little help please?
You can have such a reference to mutable objects.
Consider this:
>>p = [[0,0,0], [0,0,0]]
x = p[0] # reference to mutable list object
x[0] = 10
p
[[10, 0, 0], [0, 0, 0]]

--
HTH,
Rob

Feb 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Christian Seberino | last post by:
How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python? Python's design is godly. I'm wondering if Ruby's is godly too. I've heard it has solid OOP design but then...
40
by: Shufen | last post by:
Hi all, Can someone who has use PHP before and know quite well about the language, tell me what are the stuffs that Python offers and PHP doesn't. A few examples will be nice. I know about the...
53
by: Michael Tobis | last post by:
Someone asked me to write a brief essay regarding the value-add proposition for Python in the Fortran community. Slightly modified to remove a few climatology-related specifics, here it is. I...
18
by: diffuser78 | last post by:
I have a python code which is running on a huge data set. After starting the program the computer becomes unstable and gets very diffucult to even open konsole to kill that process. What I am...
0
by: skip | last post by:
After much wailing and gnashing of teeth the past couple of days, I managed to move (most of?) the content from the MacPython wiki to the main Python wiki (*). All pages were created as subpages...
5
by: vishnu | last post by:
Hi there, I am embedding python 2.5 on embedded system running on RTOS where I had strict memory constraints. As python is a huge malloc intensive application, I observed huge memory...
41
by: none | last post by:
Hello, IIRC, I once saw an explanation how Python doesn't have "variables" in the sense that, say, C does, and instead has bindings from names to objects. Does anyone have a link? Thanks, ...
5
by: Santiago Romero | last post by:
Is there a way to check the REAL size in memory of a python object? Something like or or something like that ...
8
by: Palindrom | last post by:
Hi everyone ! I'd like to apologize in advance for my bad english, it's not my mother tongue... My girlfriend (who is a newbie in Python, but knows Perl quite well) asked me this morning why...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.