IsString

Steve Holden steve at holdenweb.com
Tue Dec 13 12:19:01 EST 2005


Tom Anderson wrote:
> On Tue, 13 Dec 2005, Steven D'Aprano wrote:
> 
> 
>>On Mon, 12 Dec 2005 18:51:36 -0600, Larry Bates wrote:
>>
>>[snippidy-doo-dah]
>>
>>
>>>I had the same thought, but reread the post.  He asks "if a given 
>>>variable is a character or a number".  I figured that even if he is 
>>>coming from another language he knows the difference between "a given 
>>>variable" and the "contents of a give variable".  I guess we will 
>>>see.... ;-).  This list is so good, he gets BOTH questions answered.
>>
>>The problem is, Python doesn't have variables (although it is 
>>oh-so-tempting to use the word, I sometimes do myself). It has names in 
>>namespaces, and objects.
> 
> 
> In what sense are the names-bound-to-references-to-objects not variables?
> 
In a very important sense, one which you should understand in order to 
understand the nature of Python.

In C if you declare a variable as (for example) a character string of 
length 24, the compiler will generate code that allocates 24 bytes to 
this variable on the stack frame local to the function in which  it's 
declared. Similarly if you declare a variable as a double-length 
floating point number the compiler will emit code that allocates 16 
bytes on the local stack-frame.

In Python a name (*not* a "variable", though people do talk loosely 
about "instance variables" and "class variables" just to be able to use 
terms familiar to users of other to languages)  is simply *bound* to a 
value. The only storage that is required, therefore, is enough to hold a 
pointer (to the value currently bound to the name). Thus assignment 
(i.e. binding to a name, as opposed to binding to an element of a data 
structure) NEVER copes the object, it simply stores a pointer to the 
bound object in the part of the local namespace allocated to that name.
> 
>>It be a subtle difference, but an important one.
> 
> 
> No, it's just spin, bizarre spin for which i can see no reason. Python has 
> variables.
> 
You appear very confident of your ignorance ;-)
> 
>>That's why, for instance, Python is neither call by reference nor call 
>>by value, it is call by object.
> 
> 
> No, python is call by value, and it happens that all values are pointers. 
> Just like java, but without the primitive types, and like LISP, and like a 
> load of other languages. Python's parameter passing is NO DIFFERENT to 
> that in those languages, and those languages are ALL described as 
> call-by-value, so to claim that python does not use call-by-reference but 
> some random new 'call-by-object' convention is incorrect, unneccessary, 
> confusing and silly.
> 
> </rant>
> 
> I'm sure this has been argued over many times here, and we still 
> all have our different ideas, so please just ignore this post!
> 
Couldn't!

I do apologise, though, for any implication you assertions are based on 
ignorance because you do demonstrate quite a sophisticated knowledge of 
what goes on under the hood. As long as you can accept that "Python 
'variables' are all references" then the rest is indeed semantics.

Of course it will be helpful for newcomers if we can adopt a standard 
terminology ...

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list