473,770 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.regionlis t), 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 1183
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
2467
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 information for element <elementName>... I would appreciate if anyone could advice where I am going wrong. TIA Here's my xsd:
1
10154
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 closes. The closing of the dropdown list can happen without changing the dropdown, hence the onchange event is not a sure way to determine that the dropdown list closed. Is this possible in Internet Explorer?
25
3049
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 { text-align: left; } <table id="testTable"> <col id="leftCol" /> <col span="2" />
2
2270
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 is submitted. I'm using javascript to change the multiple property of the select element to true and then I'm looping through each option to change its selected property to true.
5
4027
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 list that will cause the appropriate element on another part of the page to be displayed pseudo code below var mydropdownlist =
0
1875
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, and you'll be left with just noisy compiler warnings and confusion. if you start a project with all char *, and char ** and even char ***, if you begin at the low level weeding out references of 'passing const char * to char * ( such as...
15
1514
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 questions with: ------------------------------------------------------------------------------------------- Now onto the issue: List's and Tuple's I don't see the distinction between the two. I mean, I understand that a list is mutable and a tuple...
0
977
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 like: "self.regionlist.append(list(self.regionlist)" and now it works fine, i.e., altering the appended list member doesn't change the copied one. -Chuckk
13
8757
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 is the behaviour I want make happen in IE. Does anyone know how to accomplish this? Thanks a lot Andy Birchall
0
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7431
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.