I am having a strange problem with classes. I'm fairly sure the
problem is with classes, anyway, because when I re-write the program
without them, it works like I'd expect it to.
When I run this program, at first, L[0].z[1] is 0, because z=[0,0].
But after I run that loop to assign different values to L[1].z[0] and
L[1].z[1], somehow the value of L[0].z[1] has changed to 1. I have no
idea why this is happening, can anyone help me?
class Stuff:
z=[0,0]
L = [Stuff(),Stuff()]
print "L[0].z[1]=%i" % L[0].z[1]
for j in range(2):
L[1].z[j] = j
print "L[0].z[1]=%i" % L[0].z[1] 1 934
cfgauss wrote: I am having a strange problem with classes. I'm fairly sure the problem is with classes, anyway, because when I re-write the program without them, it works like I'd expect it to.
When I run this program, at first, L[0].z[1] is 0, because z=[0,0]. But after I run that loop to assign different values to L[1].z[0] and L[1].z[1], somehow the value of L[0].z[1] has changed to 1. I have no idea why this is happening, can anyone help me?
class Stuff: z=[0,0]
This is a class attribute (shared by all instances of Stuff), not an
instance attribute.
To define instance attribute, the syntax is:
class Stuff(object):
def __init__(self):
self.z = [0, 0]
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: George Sakkis |
last post by:
I'm looking for a design to a problem I came across, which goes like
this (no, it's not homework):
1. There is a (single inheritance) hierarchy of domain classes, say
A<-B<-..<-Z (arrows point...
|
by: Omer van Kloeten |
last post by:
The Top Level Design:
The class Base is a factory class with a twist. It uses the Assembly/Type
classes to extract all types that inherit from it and add them to the list
of types that inherit...
|
by: Merlin |
last post by:
Hi
Imagine the following classes (A class diagram will help)
BASE, A, B, C, D, E, F, G.
A, B, C, D, G inherit from BASE.
E, F inherit from D.
|
by: Leslaw Bieniasz |
last post by:
Cracow, 20.09.2004
Hello,
I need to implement a library containing a hierarchy of classes
together with some binary operations on objects. To fix attention,
let me assume that it is a...
|
by: TheOne |
last post by:
I have two classes:
class OntologyParser
{
...
protected:
virtual void startElement(void *userData, const char *name, const
char **atts);
virtual void endElement(void *userData, const char...
|
by: Alexis |
last post by:
Hello,
I have a set of classes I created from schema files using the xsd.exe
tool. I'm using namespaces in the clases ( I had to because I have
some classes with the same name but not the same...
|
by: toton |
last post by:
Hi,
I have little confusion about static memory allocation & dynamic
allocation for a cluss member.
I have class like
class Bar{
public:
explicit Bar(){
cout<<"bar default"<<endl;
}
|
by: Florian Lindner |
last post by:
Hello,
I have these class declarations
class CBauteil {
private:
int m_iNumber;
int m_iWeight;
public:
int getNumber();
void setNumber(int);
|
by: Nathan Sokalski |
last post by:
I have several CustomControls that I have written for my project. However,
when I try to compile I recieve the following warning & errors:
Warning 32 Could not resolve this reference. Could not...
|
by: weird0 |
last post by:
How does C++ and C# solve the Diamond problem? With the help of
interfaces that is.
Can anyone elaborate .......
Regards
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |