473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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
1 1164
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Wole Ogunremi | last post by:
I guess this is a well asked question but it is tripping me up! I'm putting a forum together allowing xhtml markup content. I am validating against a schema but getting "Could not find schema...
1
by: Rod Early | last post by:
I need to know when the select element's dropdown list is opened (as when the user clicks on the arrow or does ALT-downarrow from the keyboard). Similarly, I need to known when the dropdown list...
25
by: Haines Brown | last post by:
I have a table with three columns, and I want the data in the first column to align left, while that in the remaining columns to align right: #testTable { text-align: right; } #leftcol {...
2
by: Rob Long | last post by:
Hi I have an HTML select element in my page and it's multiple property is disabled (one item at a time mode) but I still want to transfer all the items in the select to the server when the form...
5
by: mantrid | last post by:
Hello Im trying to find the correct syntax to use to determine whether which form element is visible on changing the value in a dropdown list I need something in the onChange of the dropdown...
0
by: d3x0xr | last post by:
Heh, spelled out in black and white even :) Const is useles... do NOT follow the path of considering any data consatant, because in time, you will have references to it that C does not handle,...
15
by: Scott | last post by:
I'm going to start grouping all my questions in one post as this is my second today, and sorta makes me feel dumb to keep having to bother you all with trivial questions. I'll just seperate my...
0
by: Chuckk Hubbard | last post by:
I solved this problem. I still don't understand why, but it seems Python was appending a reference to the first element at the end of the list, rather than copying the data. I used something...
13
by: andypb123 | last post by:
Hello, The onchange event fires in IE6 in a SELECT element when scrolling through the list with the up and down arrows on the keyboard. In Firefox it only fires after you hit the enter key, which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.