By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,996 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,996 IT Pros & Developers. It's quick & easy.

How to call a Class?

P: 4
how do you call a Class in python? i am tries to call a Class, when the class in the on the same page as def main().
May 4 '07 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
how do you call a Class in python? i am tries to call a Class, when the class in the on the same page as def main().
I am not sure what you mean by 'on the same page as def main()'.
Expand|Select|Wrap|Line Numbers
  1. >>> class Hello:
  2. ...     def __init__(self):
  3. ...         print 'Hello'
  4. ...     def __str__(self):
  5. ...         return 'The Hello class has been instantiated'
  6. ...     
  7. >>> def main():
  8. ...     a = Hello()
  9. ...     print a
  10. ...     
  11. >>> main()
  12. Hello
  13. The Hello class has been instantiated
  14. >>> 
May 4 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.