473,327 Members | 1,997 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,327 software developers and data experts.

Re: Python internals

Peter Anderson wrote:
Hi! I am slowly teaching myself Python. I was reading David Beazley's
excellent book "Python - Essential Reference"; in particular about
variables. Let me quote:

"Python is a dynamically typed language in which names can represent
values of different types during the execution of a program. In fact the
names used in the program are really just labels for various quantities
and objects. The assignment operator simply creates an association
between a name and a value. This is different from C, for example, in
which a name (variable) represents a fixed size and location in memory..."

As an old mainframe programmer, I understand the way C does things with
variable but this text got me wondering how Python handles this
"association" between variable name and value at the lower level. Is it
like a fifo list?

If there is any Python guru that can help I would be most interested in
your thoughts.

Regards,
Peter
Names are pointers in Python that point to values in memory. Names are "bound"
to these values with assignment. Names are NOT buckets where you put values as
is the case (or thought process) in other languages. Example:

a = list(1,2,3)
b = a

Now a AND b point to the same list in memory

Note: if you wanted a COPY of the list you should do:

b = a[:]

Names can also point to functions, class instances, class methods or any other
object. Example:

def foo(arg):
print arg
bar = foo

Now you can call bar(arg) or foo(arg) and it will do exactly the same thing.

If you ever wrote assembler than you will begin to understand. varibles are
pointers to objects, not buckets were stuff is stored.

Hope this helps some.

-Larry
Jul 15 '08 #1
5 1316
Op Tue, 15 Jul 2008 09:29:58 -0500, schreef Larry Bates:
Names are pointers in Python that point to values in memory.
But "pointers" doesn't have the same meaning as in "C" here.

Memory in Python is not (necessarily) an "array of bytes"; how & where
the values are stored in "physical memory" at any time during the
lifetime of an object is an implementation detail.

Maybe you can compare it to how a (university) library works: you ask a
librarian for a book named "The Taste Of Man by Slavenka Draculić" and
they fetch it for you, using whatever internal classification/retrieval
system they use.
--
JanC
Jul 15 '08 #2
Larry Bates <la*********@websafe.com`writes:
Names are pointers in Python that point to values in memory.
The term "pointer" carries much extra baggage for a programmer
thinking of C (as the original poster is). Python names give no access
to the "address" of the value, and don't need to be "de-referenced".

I've had better success explaining Python names to such people in
terms of "references": there is no "address" and no "de-reference"
needed. Access the name, and you get its value.

On the other hand, I prefer to avoid using either of those concepts,
and talk in terms of "name tags" or "sticky notes". Names (and other
references, like list elements) attach to the object, and have no
other value or purpose. They don't affect the object they're attached
to; they are entirely independent of other bindings to the same
object; they re-bind to another object with no history of what they
were bound to previously.

The analogy is quite robust, and carries none of the confusing baggage
of "variable" or "pointer" or other overloaded language terms.

--
\ “Are you pondering what I'm pondering?” “I think so, Brain, but |
`\ I don't think Kay Ballard's in the union.” —_Pinky and The |
_o__) Brain_ |
Ben Finney
Jul 15 '08 #3
Ben Finney wrote:
Larry Bates <la*********@websafe.com`writes:
>Names are pointers in Python that point to values in memory.

The term "pointer" carries much extra baggage for a programmer
thinking of C (as the original poster is). Python names give no access
to the "address" of the value, and don't need to be "de-referenced".

I've had better success explaining Python names to such people in
terms of "references": there is no "address" and no "de-reference"
needed. Access the name, and you get its value.

On the other hand, I prefer to avoid using either of those concepts,
and talk in terms of "name tags" or "sticky notes". Names (and other
references, like list elements) attach to the object, and have no
other value or purpose. They don't affect the object they're attached
to; they are entirely independent of other bindings to the same
object; they re-bind to another object with no history of what they
were bound to previously.

The analogy is quite robust, and carries none of the confusing baggage
of "variable" or "pointer" or other overloaded language terms.
You are, of course, correct. Since I'm not a C programmer, the term pointer
doesn't carry the same "baggage" as it might to others. The "problem" I had
when I first started is that people were using such "vague" terms like names,
tags, etc. that it had no meaning to me. I like your idea of "references".

-Larry

Jul 15 '08 #4
Peter Anderson <pe************@internode.on.netwrites:
If Python doesn't do it like C and the others then what mechanism does
it use
You've already been pointed to it, but here it is again:
<URL:http://effbot.org/zone/python-objects.htm>

--
\ “I may disagree with what you say, but I will defend to the |
`\ death your right to mis-attribute this quote to Voltaire.” |
_o__) —Avram Grumer, rec.arts.sf.written, May 2000 |
Ben Finney
Jul 16 '08 #5
Peter Anderson wrote:
Thanks everyone! Just a quick correction - "as the original poster is"
is a bit of a jump that does not reflect my original question. I DO
understand how C and other programming languages handle variables
internally (the bits of actual memory reserved, etc. etc.) and that's
why I asked the question in the first place.

If Python doesn't do it like C and the others then what mechanism does
it use - it's the sort of issue that helps me understand how the
language is interacting with the underlying operating system/hardware.
The easiest way to think of this is that Python uses mostly dictionaries
dictionaries for namespaces, and a few places it uses other techniques
if there are over-riding considerations that make the dictionaries
impractical in particular cases. Python performance would be crippled
if their dictionary implementation(s) slowed down, much as C performance
would suffer is access to RAM slowed down.

--Scott David Daniels
Sc***********@Acm.Org
Jul 16 '08 #6

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

Similar topics

36
by: Armin Rigo | last post by:
Hi! This is a rant against the optimization trend of the Python interpreter. Sorting a list of 100000 integers in random order takes: * 0.75 seconds in Python 2.1 * 0.51 seconds in Python...
9
by: F. GEIGER | last post by:
I've dev'ed a Python prototype of an app, that besides the internals making it up has a gui. While test-driven dev'ing the app's internals in Python is fun as usual, dev'ing the GUI is not so...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
4
by: schwehr | last post by:
Hi All, Does anyone have a good template that I might use for writing a python paper in latex/bibtex? I've got the paper mostly done, but am having issues with the references. I am definitely...
3
by: Wolfgang Keller | last post by:
Hello, this is a potentially veeery dumb question, but: - If an application supports VBA as a macro language, - and if you can execute Python code from within a VBA script (how?) - and if the...
23
by: Simon Hengel | last post by:
Hello, we are hosting a python coding contest an we even managed to provide a price for the winner... http://pycontest.net/ The contest is coincidentally held during the 22c3 and we will be...
20
by: walterbyrd | last post by:
Reading "Think Like a Computer Scientist" I am not sure I understand the way it describes the way objects work with Python. 1) Can attributes can added just anywhere? I create an object called...
40
by: brad | last post by:
Will len(a_string) become a_string.len()? I was just reading http://docs.python.org/dev/3.0/whatsnew/3.0.html One of the criticisms of Python compared to other OO languages is that it isn't OO...
4
by: Ognjen Bezanov | last post by:
Hello All, I am a third year computer science student and I'm the process of selection for my final year project. One option that was thought up was the idea of implement my own version of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.