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

More than one element of list changing when only one should be

P: n/a
Hello.
This program is clunky, I know; I'm not a programmer, but I need to
use this program, so I'm writing it.
The problem:
I have a cursor following the mouse that shows frequency ratios of
potential notes in relation to 1/1 (something like Middle C). At any
time, the user may hit "t" to move 1/1 to wherever the cursor is.
There is also the option to use many regions, so that some of the
notes in the score, in region 0, for instance, can have 1/1 as their
base, and others, in region 1 for instance, could have perhaps 3/2 as
their base.

The program starts out with 2 existing regions, region 0 = 1/1, and
region 1 = 3/2. If the user hits r+NUM, the cursor switches to region
NUM. If NUM is longer than the list of regions (self.regionlist), a
new region is appended with the same base as the current one, and the
cursor goes to that region.

SO, if you start this program, then:
1) move the cursor around a little;
2) hit 'r' and '1' at the same time - now you are in region 1;
3) hit 'r' and '0', now region 0;
4) hit 'r' and '2', now a new region 2 is created with the same
parameters as region 0, and self.regionlist is appended with the new
info - now you're in region 2;
5) move the mouse until the fraction reads anything other than 1/1;
6) hit 't' to transpose the current region by that fraction;

You can see by the output in the text window that self.regionlist[0]
AND self.regionlist[2] have been updated. Only [2] should have been
changed.

7) hit 'r' and '0', and see that region 0 has now changed its base to
match region 2.

I hope someone is curious enough to get through this and help me. I
tried extracting the function in question into its own mini-file and
the problem didn't happen. I can't think of any reason these lines:

self.regionlist[self.hregion][0] = self.curnum
self.regionlist[self.hregion][1] = self.curden
self.regionlist[self.hregion][3] = self.octave11 = self.yadj

should change self.regionlist[0] AND self.regionlist[2] in the same
call, but they do. Also, if I add more regions in series, they all
update each other.

Thanks for your time.

-Chuckk

--
http://www.badmuthahubbard.com
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Chuckk Hubbard wrote:
I can't think of any reason these lines:

self.regionlist[self.hregion][0] = self.curnum
self.regionlist[self.hregion][1] = self.curden
self.regionlist[self.hregion][3] = self.octave11 = self.yadj

should change self.regionlist[0] AND self.regionlist[2] in the same
call, but they do. *Also, if I add more regions in series, they all
update each other.
The likely explanation is that regionlist[0] and regionlist[2] are actually
the same list. Throw in a

print self.regionlist[0] is self.regionlist[2]

to verify. The two most common reasons for that:

class A:
items = [] # class attribute, shared between all instances
def f(items=[]): # default argument, shared between all calls
# without explicit items argument
return items

Peter
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.