In article mailman.22.1266722722.4577.python-l...@python.org,
Michael Pardee python-l...@open-sense.com wrote:
I'm relatively new to python and I was very surprised by the following
behavior:
http://starship.python.net/crew/mwh/hacks/objectthink.html
--
Aahz (a...@pythoncraft.com) *
* Michael Pardee:
I'm relatively new to python and I was very surprised by the following behavior:
a=1
b=2
'a' refers to an object representing the integer 1.
Since 1 is an immutable value you can just as well think of it as 'a' containing
the value 1, because a reference to an immutable
On 02/21/10 15:21, Steven D'Aprano wrote:
So it looks like variables in a list are stored as object references.
Python doesn't store variables in lists, it stores objects, always.
Even Python variables aren't variables *grin*, although it's really
difficult to avoid using the term. Python
On Sat, 20 Feb 2010 23:44:29 -0800, Carl Banks wrote:
On Feb 20, 10:50 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
What makes you say that?
[...]
I don't even understand this.
[...]
I'm just confused why you think that
lexical scoping is equivalent to references that
Michael Pardee python-l...@open-sense.com wrote in message
news:mailman.22.1266722722.4577.python-l...@python.org...
I'm relatively new to python and I was very surprised by the following
behavior:
a=1
b=2
mylist=[a,b]
print mylist
[1, 2]
a=3
print mylist
[1, 2]
Whoah! Are python lists
Steven D'Aprano wrote:
On Sat, 20 Feb 2010 22:31:44 -0800, Carl Banks wrote:
The one place where Python does have references is when accessing
variables in an enclosing scope (not counting module-level).
What makes you say that?
I think Carl is talking about cells, which *are* actually
I'm relatively new to python and I was very surprised by the following behavior:
a=1
b=2
mylist=[a,b]
print mylist
[1, 2]
a=3
print mylist
[1, 2]
Whoah! Are python lists only for literals? Nope:
c={}
d={}
mydlist=[c,d]
print mydlist
[{}, {}]
c['x']=1
print mydlist
[{'x': 1}, {}]
On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee
python-l...@open-sense.com wrote:
I'm relatively new to python and I was very surprised by the following
behavior:
a=1
b=2
mylist=[a,b]
print mylist
[1, 2]
a=3
print mylist
[1, 2]
Whoah! Are python lists only for literals? Nope:
On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee
python-l...@open-sense.comwrote:
But what would be the python way to accomplish list of variables
functionality?
The problem is... Python doesn't have variables. At least not in the way
that you may be used to from other languages. Yeah, it's
Michael Pardee python-l...@open-sense.com writes:
But what would be the python way to accomplish list of variables
functionality?
You'll need to explain what “list of variables” functionality is.
If you mean “collection of name-to-value mappings”, the native mapping
type in Python is ‘dict’.
]
function(mylist)
assert x == 1
and the assertion failed, even though you never passed x to the function.
Such behaviour could easily turn into a never-ending source of bugs.
So it looks like variables in a list are stored as object references.
Python doesn't store variables in lists
On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee
python-l...@open-sense.com wrote:
But what would be the python way to accomplish list of variables
functionality?
You're looking for namespaces, AKA dicts.
vars = {}
vars['a'] = 1
vars['b'] = 2
mylist = ['a', 'b']
print [vars[i] for i in
On Feb 20, 7:25 pm, Michael Pardee python-l...@open-sense.com wrote:
I'm relatively new to python and I was very surprised by the following
behavior:
a=1
b=2
mylist=[a,b]
print mylist
[1, 2]
a=3
print mylist
[1, 2]
Whoah! Are python lists only for literals? Nope:
c={}
On Sat, 20 Feb 2010 22:31:44 -0800, Carl Banks wrote:
The one place where Python does have references is when accessing
variables in an enclosing scope (not counting module-level).
What makes you say that?
But these
references aren't objects, so you can't store them in a list, so it
On Feb 20, 10:50 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
On Sat, 20 Feb 2010 22:31:44 -0800, Carl Banks wrote:
The one place where Python does have references is when accessing
variables in an enclosing scope (not counting module-level).
What makes you say that?
15 matches
Mail list logo