Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > pointers

Reply
Thread Tools

pointers

 
 
km
Guest
Posts: n/a
 
      12-28-2003
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



 
Reply With Quote
 
 
 
 
Aahz
Guest
Posts: n/a
 
      12-28-2003
In article <mailman.142.1072628533.684.python->,
km <> wrote:
>
>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?
--
Aahz () <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote
programs, then the first woodpecker that came along would destroy civilization.
 
Reply With Quote
 
 
 
 
Maxim Khesin
Guest
Posts: n/a
 
      12-28-2003
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.


km wrote:

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

 
Reply With Quote
 
sdd
Guest
Posts: n/a
 
      12-28-2003
km wrote:

> 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


 
Reply With Quote
 
Matthew Scott
Guest
Posts: n/a
 
      12-28-2003
km wrote:

> 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.

>>> class Foo:

.... pass
....

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

>>> f1 = Foo()


Add an attribute to the Foo instance we just created.

>>> f1.xyz = 5


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.

>>> f2 = f1


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

>>> f2.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.

>>> f2.xyz = 6
>>> f1.xyz

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)

>>> id(f1)

1075959340
>>> id(f2)

1075959340
>>> id(f1) == id(f2)

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.

>>> f2 = Foo()
>>> f2.xyz

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.

>>> id(f2)

1075959372
>>> id(f1) == id(f2)

False


--
Matthew Scott <>

 
Reply With Quote
 
John Roth
Guest
Posts: n/a
 
      12-28-2003

"km" <> wrote in message
news:mailman.142.1072628533.684.python-...
> 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

>
> regards,
> thanks
> KM
>
>
>



 
Reply With Quote
 
Mathias Waack
Guest
Posts: n/a
 
      12-28-2003
Aahz wrote:

> In article <mailman.142.1072628533.684.python->,
> km <> wrote:
>>
>>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?


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

Mathias
 
Reply With Quote
 
Jp Calderone
Guest
Posts: n/a
 
      12-29-2003
On Sun, Dec 28, 2003 at 01:48:36PM -0500, John Roth wrote:
>
> "km" <> wrote in message
> news:mailman.142.1072628533.684.python-...
> > 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.
>


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


 
Reply With Quote
 
John Roth
Guest
Posts: n/a
 
      12-29-2003

"Jp Calderone" <> wrote in message
news:mailman.150.1072662746.684.python-...
> On Sun, Dec 28, 2003 at 01:48:36PM -0500, John Roth wrote:
> >
> > "km" <> wrote in message
> > news:mailman.142.1072628533.684.python-...
> > > 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.
> >

>
> 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
>
> Jp
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
Does deleting a container of pointers also delete the (contained) pointers? Xamalek C++ 7 11-04-2003 04:17 PM
c++: pointers to pointers A C++ 3 10-29-2003 01:15 PM
pointers to pointers // exception handling error muser C++ 3 09-18-2003 06:19 PM
Template specialization of pointers with function pointers Phil C++ 1 09-16-2003 02:17 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57