On Fri, Aug 24, 2012 at 3:56 AM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > But name bindings are a kind of variable. Named memory locations are a > *different* kind of variable. The behaviour of C variables and Python > variables do not follow the Liskov Substitution Principle -- you can't > rip out the entire "names bound to objects" machinery of Python and > replace it with C-like named memory locations without changing the high- > level behaviour of Python. And so by some ways of thinking it is *wrong* > to treat name bindings and memory locations as "the same sort of entity". > Hence, if C variables are variables, then Python name bindings can't be.
Yet Python's variables are extremely close to C's pointer variables. If you allocate all your "real data" on the heap and do everything with pointers, you'll have semantics very similar to Python's (except that things aren't refcounted, so you have massive memory leaks). In fact, that's how the Python-C API handles things - a PyObject* basically _is_ a Python object, as far as C's concerned. But again, that probably doesn't help explain the variables. Unless you've come from (or can at least imagine) an environment in which you use pointers for *everything*. ChrisA -- http://mail.python.org/mailman/listinfo/python-list