Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread eryksun
On Tue, Nov 26, 2013 at 6:13 AM, Dominik George wrote: > Now when zou instantiate the class, then the dictionary is copied to the > instance (carying references to the same data inside it, mind you!), Perhaps the above is just a simple mistake of wording, but to be clear, the class dict isn't cop

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Mark Lawrence
On 26/11/2013 10:00, Dominik George wrote: Hi Reuben, class Animal(): flag = True print flag Are you sure you know what this does ;)? Normally, you initialize all variables in the constructor. Wrong. You normally initialise names in the initialiser which is called __init__

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Reuben
Yes! I got my answer now. Thanks all @Dominick: sorry about my explanation. On 26-Nov-2013 4:24 PM, "Alan Gauld" wrote: > On 26/11/13 07:30, Reuben wrote: > >> Hi, >> >> Following is my code: >> # >> class Animal(): >> >>flag = True >>p

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Steven D'Aprano
On Tue, Nov 26, 2013 at 01:00:18PM +0530, Reuben wrote: > Hi, > > Following is my code: > # > class Animal(): > > flag = True > print flag This "flag" is a class attribute, which means it is shared by all instances. Every Animal will see t

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Dominik George
Hi, > By setting test.flag you are creating a new instance level attribute > that exists only within the test instance. That's legal Python > but usually its not a good idea to have different instances of > the same class having different attributes. maybe this becomes clearer by breaking down th

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Alan Gauld
On 26/11/13 07:30, Reuben wrote: Hi, Following is my code: # class Animal(): flag = True print flag def __init__(self,name): self.name = name print self.name def walk(self

Re: [Tutor] How to set variables inside a class()

2013-11-26 Thread Dominik George
Hi Reuben, > class Animal(): > > flag = True > print flag Are you sure you know what this does ;)? Normally, you initialize all variables in the constructor. > test.flag = False > 1)Inside the Animal class(), How can I set the variable 'flag' to FALSE? Your qustion is a bit u

[Tutor] How to set variables inside a class()

2013-11-26 Thread Reuben
Hi, Following is my code: # class Animal(): flag = True print flag def __init__(self,name): self.name = name print self.name def walk(self): print "I am walking" if __name__ == '__main__':