By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,932 Members | 1,908 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,932 IT Pros & Developers. It's quick & easy.

Reference gotcha

P: n/a
Hi all,
This interested me:
a1 = a2 = {}
a1['blah'] = 1
a2 {'blah': 1} a1 == a2 True
Whereas ...

b1 = b2 = 0
b1 += 1
b2 0 b1 == b2

False

So how should one create a robust alias for a numeric type?

This bit me when I was trying to do the following in a class:
def __init__(self, data):
a = self.a = {}
b = self.b = {}
c = self.c = 0

# and increment them here ...

Best regards,
Ed Schofield
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ed Schofield wrote:
Hi all,
This interested me:

a1 = a2 = {}
a1['blah'] = 1
a2
{'blah': 1}
a1 == a2
True
Whereas ...
b1 = b2 = 0
b1 += 1
b2
0
b1 == b2


False

So how should one create a robust alias for a numeric type?

This bit me when I was trying to do the following in a class:
def __init__(self, data):
a = self.a = {}
b = self.b = {}
c = self.c = 0

# and increment them here ...

Best regards,
Ed Schofield


Standard trick is to use single element list or just a small object with
integer field.

hth,
anton.
Jul 18 '05 #2

P: n/a
anton muhin wrote:

Standard trick is to use single element list or just a small object with
integer field.


But why do that when "self." is already a small object with an integer
field?

Paul Prescod

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.