On Tue, Jun 16, 2015 at 9:17 AM,  <subhabrata.bane...@gmail.com> wrote:
> On Tuesday, June 16, 2015 at 8:35:39 PM UTC+5:30, Laura Creighton wrote:
>> In a message of Tue, 16 Jun 2015 06:56:12 -0700,  writes:
>> >ii) In a class how may I include if __name__ == "__main__": with multiple 
>> >methods? But I think this is easy question there should be lot of web help.
>> >
>> >If anyone may kindly suggest.
>> >
>> >Regards,
>> >Subhabrata Banerjee.
>>
>> There is something wrong in the way you are thinking about this.
>> You don't _want_ to stick if __name__ = "__main__":
>> into every class you write.
>>
>> See if reading this helps.
>> http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm
>>
>> Laura
>
> Hi,
> Thanks. The scipy issue seems solved. But this silly issue is giving so much 
> of time. I am checking. Please see a sample code,
>
> import sys
> sys.stderr = sys.stdout
> class Colors:
>     def Blue(self):
>         self.var="This is Blue"
>         print self.var
>     def Red(self):
>         print self.var
>
>
>
> if __name__ == "__main__":
>     Colors().Blue() #THIS IS FINE
>     Colors().Red() #NOT FINE

I'm assuming that when you run this, you get the output "This is Blue"
followed by an AttributeError from Colors.Red complaining that the var
attribute is not set. If you want this to work, then maybe you should
set the attribute.

But as Laura noted, you probably don't want to be calling more than
one thing in your if __name__ == "__main__" block. Just call the entry
point of your program.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to