Python IRC dictatorship

John Hunter jdhunter at ace.bsd.uchicago.edu
Sat Nov 23 11:11:30 EST 2002


>>>>> "Timothy" == Timothy Rue <threeseas at earthlink.net> writes:

    Timothy> they exist here too.

They are everywhere <wink>

    Timothy> so what the fuck don't you understand about a named
    Timothy> container that can hold changable information? Like a
    Timothy> variable or a file.

If you say named container, to a python coder, they will think list,
tuple, dict and maybe string.  They definitely would not initially
think about a 'variable or file'.

"variables" in python are a little different than in other programming
languages.  python has "names" for objects.  This example illustrates
one of the initially surprising ways names work

  x = []
  y = []
  x.append(1)
  print y

x and y are just names for the same object (the empty list).  When you
change that object referring to it by the name 'x', the changes are
seen when you refer to it by it's other name 'y'.  So y now equals
[1].

A variable in the sense you are using it is not a "container that can
hold changeable information".  The variable is a name and not a
container.  This is a difference worth remembering and understanding.

Now, on to real containers.  

In the example of a list

  x = [1,2,3]

A python coder would say x is the name of a container (list) that
holds changeable (mutable) information (in real life the would call it
a "list" or more generally a "mutable sequence type").  In the example

  y = (1,2,3)

A python coder would say y is the name of a container (tuple) that
hold unchangeable (immutable) information.  So we can say x[1] = 12 but
cannot say y[1] = 12.

    Timothy> Or hell, how about variables in files..

Hmm, this one is tougher.  matlab has m-files that let you save named
variables in a file.  Python has pickle, but it's not quite the same
thing.  You might think of a file as something that can hold
(changeable) information.  Or you might think of it as holding the
values of your variables (named objects).  But because python thinks
in terms of objects with names, you wouldn't be inclined to think
about "variables in files".

    Timothy> Are you one of them arrogant jerks in power that haven't
    Timothy> a clue, too.

    Timothy> Of course you are, why else woud you think I'm delusional
    Timothy> about such a simple common concept?

It's not really as simple as you make it out to be.  The subtleties in
the simple concepts of "variables" and "named containers" trip up
almost all newcomers to python at one point or another.

just-my-clueless-arrogant-jerk-with-no-power two cents
John Hunter





More information about the Python-list mailing list