473,802 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

small program with strange behavior

The below small program is giving strange behavior. At the bottom of the code,
please find "this works" and "this doesn't work" comments. Why does one
work and the other not?

TIA.

#!/usr/bin/python

import string

class move_class:
bad = 'Invalid initializer'

def __init__(self,s tr,rank_black,r ank_white):
self.text = str
self.children = []
self.rank_black = rank_black
self.rank_white = rank_white
if str[0:2] == 'B[':
#if move_class.prio r != '' and move_class.prio r != 'W':
# raise move_class.bad
if str[1:2] != '[' or str[4:5] != ']':
raise move_class.bad
self.letters = string.lower(st r[2:4])
move_class.prio r = 'B'
self.color = 'B'
self.ranks=[rank_black]
elif str[0:2] == 'W[':
#if move_class.prio r != 'B':
# raise move_class.bad
if str[1:2] != '[' or str[4:5] != ']':
raise move_class.bad
self.letters = string.lower(st r[2:4])
#move_class.pri or = 'W'
self.color = 'W'
self.ranks=[rank_white]
else:
raise move_class.bad
self.strrow = self.letters[0:1]
self.strcol = self.letters[1:2]
trow = ord(self.strrow ) - ord('a')
if trow >= 11:
trow = trow - 1
self.row = trow
tcol = ord(self.strcol ) - ord('a')
if tcol >= 11:
tcol = tcol - 1
self.col = tcol

def rotate90(self):
size=19
self.row,self.c ol = self.col,size - self.row - 1

def copy(self):
newmove = move_class(self .text,self.rank _black,self.ran k_white)
return newmove

def __str__(self):
t = ''
for i in self.ranks:
t = t + str(i) + ' '
return str(self.row)+' ,'+str(self.col )+' '+str(self.colo r)+' '+\
t

move=move_class ('B[qp]',-4,-1)

newgame=[move]

for r in range(4):
for move_no in range(0,len(new game)):
# this doesn't work
newmove = newgame[move_no].copy()
# this works
#newmove = newgame[move_no]
newmove.rotate9 0()
newgame[move_no]=newmove
print newgame[move_no]
Jul 18 '05 #1
1 1398
Dan Stromberg wrote:

The below small program is giving strange behavior. At the bottom of the code,
please find "this works" and "this doesn't work" comments. Why does one
work and the other not?


You might find people more willing to respond if you (a) shorten your
not-so-small code down to the smallest size that reproduces the problem
you are seeing, and (b) define more clearly what "this works" and "this
doesn't work" actually mean. Are you getting exceptions? Some functionality
that is not doing the right thing? (If so, maybe tell people what the darn
thing is supposed to do rather than making them guess.)

Some people might read all that, execute it, etc, but most of us
don't have time.

-Peter
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
2879
by: Robert Gamble | last post by:
I was taking a look at some of the C puzzles at: http://purana.csa.iisc.ernet.in/~gkumar/cquestions.html and have not had any trouble with any of them except for the first one which is reproduced below: The following C program segfaults of IA-64, but works fine on IA-32. int main() { int* p; p = (int*)malloc(sizeof(int));
1
1124
by: ralphsieminsky | last post by:
I am seeing a strange behavior with a managed/unmanaged C++ program. The program is a large application made of DLLs, COM components, and an exe. When I recompile the exe with /clr a problem occurs: at some point, deep down the stack far from main() and far from the managed to native transition, a call to IXMLDOMNode::selectSingleNode through a ComPtr<IXMLDOMNode> fails. Under the debugger, several "First-chance exception - interface...
6
2276
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to the same method (aka delegate?). I use the Tag property within this method to determine what user action is taking place. Very simple: When adding toolbar button: tbButton.Click += new...
8
3090
by: Mike S | last post by:
Hi all, I noticed a very slight logic error in the solution to K&R Exercise 1-22 on the the CLC-Wiki, located at http://www.clc-wiki.net/wiki/KR2_Exercise_1-22 The exercise reads as follows: "Write a program to 'fold' long input lines into two or more shorter
10
1823
by: yaniv.dg | last post by:
hi all, i'm bumping into smething very starnge its very simple code but from some reason the program is acting strange this is my code: #include<stdio.h> #include<conio.h> void main(void) { int a,c; char b;
18
2862
by: sam_cit | last post by:
Hi Everyone, int main() { printf("not included stdio.h"); } Yes, i haven't included stdio.h and my compiler would generate a warning and would assume that it would return a int, my question is how does the linker manage to link the function invocation to the proper
169
9225
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide untaking to create a toolchain for it. Way back when, there used to be something called "Small C". I wonder if the creator(s) of that would want to embark on creating a nice little Small C++ compiler devoid of C++ language features that make...
73
2836
by: Rajeet Dalawal | last post by:
Good day group. I was asked in an interview to explain the behavior of this program. void main() { char *s = "abc"; int *i = (int *) s; printf("%x", *i); }
9
1936
by: xiao | last post by:
It always dumped when I tried to run it... But it compiles OK. What I want to do is to do a test: Read information from a .dat file and then write it to another file. The original DAT file is like this : (very simple..........) 010001010110001101010101010101010101010101 #include<stdio.h>
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10532
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...
0
10302
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10281
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
10058
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
7597
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
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
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

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.