* 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 va
In article ,
Michael Pardee 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) <*> http://www.pythoncraft.com/
"Many customs in this life persist
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 ob
"Michael Pardee" 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 only for literals? Nope
On Sat, 20 Feb 2010 23:44:29 -0800, Carl Banks wrote:
> On Feb 20, 10:50 pm, Steven D'Aprano 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 can't be pu
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. P
On Feb 20, 10:50 pm, 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?
>
> > But these
> > references a
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, 7:25 pm, Michael Pardee 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
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 mylis
On Sat, 20 Feb 2010 21:25:19 -0600, Michael Pardee wrote:
> I'm relatively new to python and I was very surprised by the following
> behavior:
[snip]
I don't see why. It's fairly unusual behaviour to want, and it would be
surprising if you did this:
def test():
x = 1
mylist = [2, 4, x]
Michael Pardee 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’. If that doesn't meet
On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee
wrote:
> 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 got data, and data
obv
On Sat, Feb 20, 2010 at 7:25 PM, Michael Pardee
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:
>
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
15 matches
Mail list logo