pointers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • km

    pointers

    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



  • Aahz

    #2
    Re: pointers

    In article <mailman.142.10 72628533.684.py thon-list@python.org >,
    km <km@mrna.tn.nic .in> wrote:[color=blue]
    >
    >may i know if there is any plans of introducing the concept of pointers
    >into python language as in C ? (atleast in future versions ?)[/color]

    There will never be pointers in Python. Why on Earth would you want
    them?
    --
    Aahz (aahz@pythoncra ft.com) <*> 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.

    Comment

    • sdd

      #3
      Re: pointers

      km wrote:
      [color=blue]
      > 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[/color]

      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
      Scott.Daniels@A cm.Org

      Comment

      • Maxim Khesin

        #4
        Re: pointers

        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:
        [color=blue]
        > 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
        >
        >
        >[/color]

        Comment

        • Matthew Scott

          #5
          Re: pointers

          km wrote:
          [color=blue]
          > 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[/color]

          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.
          [color=blue][color=green][color=darkred]
          >>> class Foo:[/color][/color][/color]
          .... pass
          ....

          Create an instance of the class. The name "f1" now refers to the instance
          we create.
          [color=blue][color=green][color=darkred]
          >>> f1 = Foo()[/color][/color][/color]

          Add an attribute to the Foo instance we just created.
          [color=blue][color=green][color=darkred]
          >>> f1.xyz = 5[/color][/color][/color]

          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.
          [color=blue][color=green][color=darkred]
          >>> f2 = f1[/color][/color][/color]

          Inspect the f2.xyz attribute to see that it contains the same value as
          f1.xyz.
          [color=blue][color=green][color=darkred]
          >>> f2.xyz[/color][/color][/color]
          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.
          [color=blue][color=green][color=darkred]
          >>> f2.xyz = 6
          >>> f1.xyz[/color][/color][/color]
          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)
          [color=blue][color=green][color=darkred]
          >>> id(f1)[/color][/color][/color]
          1075959340[color=blue][color=green][color=darkred]
          >>> id(f2)[/color][/color][/color]
          1075959340[color=blue][color=green][color=darkred]
          >>> id(f1) == id(f2)[/color][/color][/color]
          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.
          [color=blue][color=green][color=darkred]
          >>> f2 = Foo()
          >>> f2.xyz[/color][/color][/color]
          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.
          [color=blue][color=green][color=darkred]
          >>> id(f2)[/color][/color][/color]
          1075959372[color=blue][color=green][color=darkred]
          >>> id(f1) == id(f2)[/color][/color][/color]
          False


          --
          Matthew Scott <netnews@golden spud.com>

          Comment

          • John Roth

            #6
            Re: pointers


            "km" <km@mrna.tn.nic .in> wrote in message
            news:mailman.14 2.1072628533.68 4.python-list@python.org ...[color=blue]
            > Hi all,
            >
            > may i know if there is any plans of introducing the concept of pointers[/color]
            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
            [color=blue]
            >
            > regards,
            > thanks
            > KM
            >
            >
            >[/color]


            Comment

            • Mathias Waack

              #7
              Re: pointers

              Aahz wrote:
              [color=blue]
              > In article <mailman.142.10 72628533.684.py thon-list@python.org >,
              > km <km@mrna.tn.nic .in> wrote:[color=green]
              >>
              >>may i know if there is any plans of introducing the concept of
              >>pointers into python language as in C ? (atleast in future versions
              >>?)[/color]
              >
              > There will never be pointers in Python. Why on Earth would you
              > want them?[/color]

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

              Mathias

              Comment

              • Jp Calderone

                #8
                Re: pointers

                On Sun, Dec 28, 2003 at 01:48:36PM -0500, John Roth wrote:[color=blue]
                >
                > "km" <km@mrna.tn.nic .in> wrote in message
                > news:mailman.14 2.1072628533.68 4.python-list@python.org ...[color=green]
                > > Hi all,
                > >
                > > may i know if there is any plans of introducing the concept of pointers[/color]
                > 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.
                >[/color]

                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


                Comment

                • John Roth

                  #9
                  Re: pointers


                  "Jp Calderone" <exarkun@intarw eb.us> wrote in message
                  news:mailman.15 0.1072662746.68 4.python-list@python.org ...[color=blue]
                  > On Sun, Dec 28, 2003 at 01:48:36PM -0500, John Roth wrote:[color=green]
                  > >
                  > > "km" <km@mrna.tn.nic .in> wrote in message
                  > > news:mailman.14 2.1072628533.68 4.python-list@python.org ...[color=darkred]
                  > > > Hi all,
                  > > >
                  > > > may i know if there is any plans of introducing the concept of[/color][/color][/color]
                  pointers[color=blue][color=green]
                  > > 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.
                  > >[/color]
                  >
                  > Easily. A pointer is basically just an integer, with a couple minor[/color]
                  extra[color=blue]
                  > operations defined upon it.. An extension type that implemented the[/color]
                  proper[color=blue]
                  > behavior would probably only be a couple hours work to implement.
                  >
                  > As for what benefit it would serve... I can't see any.[/color]

                  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[color=blue]
                  >
                  > Jp
                  >
                  >[/color]


                  Comment

                  Working...