pointers

K

km

Hi all,

may i know if there is any plans of introducing the concept of pointers into python language as in C ? (atleast in future versions ?)

regards,
thanks
KM
 
A

Aahz

may i know if there is any plans of introducing the concept of pointers
into python language as in C ? (atleast in future versions ?)

There will never be pointers in Python. Why on Earth would you want
them?
 
M

Maxim Khesin

No.
Lack of direct support for pointers was a conscious decision of the
language designer. Raw pointer usage is annecessary evil as far as
python's target programs are concerned. If you absolutely need pointer
aceess you can get them via 3d party ctypes module.
 
S

sdd

km said:
Hi all,
may i know if there is any plans of introducing the concept of pointers into python language as in C ? (atleast in future versions ?)
regards,
thanks KM

Nope. I believe the official line is "YAGNI" (You Aint Gonna Need It).
Pointers can be fun to create interesting code, bugs and hacks, but
there is little to use them for. If you are wanting to use a familiar
structure, it won't happen here. If you think you have a _real_world_
case for it here, we can often explain why you don't really need it.
The _real_world_ bit means: find an example we can have intuitions
about, not simply foos, frobs, and mumbles.

By the way, you might think of python names as pointers to objects,
or integers as list (or string or tuple or array)-based pointers where
the list the pointer comes from is kept specific. If you want, you
could even create a class named Pointer to hide the list the pointer
is based on. We'd generally advise against this, but...

-Scott David Daniels
(e-mail address removed)
 
M

Matthew Scott

km said:
Hi all,

may i know  if  there is any plans of  introducing the concept of pointers
into python language as in C ?  (atleast in future versions ?)

regards,
thanks
KM

Python is much more "high-level" than C or similar languages. As such there
is no real need for a concept such as pointers. Instead, Python uses the
concept of references to connect variable names with the objects they
represent.

For instance, here is an example that demonstrates how two variable names
can "point" (or "refer") to the same object. The >>> and ... are the
prompts that would be output by the Python interactive interpreter if you
were to run this example code in it.

(After you read this, you might also check out the "Names" and "Assignment"
section of this web page: http://www.effbot.org/zone/python-objects.htm)

Create an empty class that we will add some attributes to below.
.... pass
....

Create an instance of the class. The name "f1" now refers to the instance
we create.

Add an attribute to the Foo instance we just created.

Assign the same instance to the name "f2". Now f1 and f2 are two separate
names, but they both refer to the exact same object.

Inspect the f2.xyz attribute to see that it contains the same value as
f1.xyz.
5

Assigning a new value to the f2.xyz attribute results in f1.xyz being
updated as well, because they are the exact same attribute.
6

You can use the id() function to show that the names "f1" and "f2" point to
the same object. (The output of id() will be different on your machine,
since they are internal identification numbers used by Python)
True

If you want "f2" to be a different object than "f1", assign a new instance
of Foo to the name "f2". Now "f2.xyz" does not exist since "f2" does not
refer to the same object as "f1" any longer.
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: Foo instance has no attribute 'xyz'

The ID of two separate objects will always be different.
False
 
J

John Roth

km said:
Hi all,

may i know if there is any plans of introducing the concept of pointers
into python language as in C ? (atleast in future versions ?)


Outside of the sheer, unadulterated wrongheadedness of
the idea, it occured to me to wonder. How would one do
this, and what benefit would it serve? Today, one can bind
anything to almost anything, so I'm having some inability
to see what one would do with pointers.

John Roth
 
M

Mathias Waack

Aahz said:
There will never be pointers in Python. Why on Earth would you
want them?

Python has pointers. Its just a matter of definition;)
Only pointer arithmetic is missing - aehm not available, no one
misses it.

Mathias
 
J

Jp Calderone

into python language as in C ? (atleast in future versions ?)


Outside of the sheer, unadulterated wrongheadedness of
the idea, it occured to me to wonder. How would one do
this, and what benefit would it serve? Today, one can bind
anything to almost anything, so I'm having some inability
to see what one would do with pointers.

Easily. A pointer is basically just an integer, with a couple minor extra
operations defined upon it.. An extension type that implemented the proper
behavior would probably only be a couple hours work to implement.

As for what benefit it would serve... I can't see any.

Jp
 
J

John Roth

Jp Calderone said:
Easily. A pointer is basically just an integer, with a couple minor extra
operations defined upon it.. An extension type that implemented the proper
behavior would probably only be a couple hours work to implement.

As for what benefit it would serve... I can't see any.

But what does it point to? What does it connect? Are we talking
about memory? I presume that's what you're talking about from
your response, but how would something like that map into a
virtual machine environment, especially one with indirect access
to the various objects? It seems like it needs a lot more definition.

John Roth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,939
Members
47,484
Latest member
JackRichard

Latest Threads

Top