Pythond类在函数中的编程方法


Pythond类如何进行相关的应用呢?这个问题需要我们不断的学习。下面我们就来介绍下Pythond类的函数编程。只有不断的学习才能更好的使用。Python属于函数是编程。

Python代码

  1. '''''   
  2. Created on 2009-11-18   
  3. @author: Administrator   
  4. '''   
  5. class MyClass(object):   
  6. '''''   
  7. classdocs   
  8. '''   
  9. cl = [1,2,"5"]   
  10. def __init__(selfparams):   
  11. '''''   
  12. Constructor   
  13. '''   
  14. print "Constructor,..."   
  15. def te(self):   
  16. print "a"   
  17. '''  
  18. Created on 2009-11-18  
  19. @author: Administrator  
  20. '''  
  21. class MyClass(object):  
  22. '''  
  23. classdocs  
  24. '''  
  25. cl = [1,2,"5"]  
  26. def __init__(selfparams):  
  27. '''  
  28. Constructor  
  29. '''  
  30. print "Constructor,..."  
  31. def te(self):  
  32. print "a" 

Python代码

  1. import Class1 '''''导入Class1.py文件'''   
  2. x = Class1.MyClass() '''''生成MyClass实例'''   
  3. x.te()   
  4. print x.cl   
  5. import moa ''''''导入另外一个模块'''   
  6. print moa.__file__   
  7. print moa.__name__   
  8. '''''try catch,捕捉异常'''   
  9. try:   
  10. print "---------------"+moa.aaa(1)   
  11. except:   
  12. print "Error"   
  13. finally:   
  14. print "finally"   
  15. print moa.aaa(1)   
  16. m = moa.M()   
  17. import Class1 '''导入Class1.py文件'''  
  18. x = Class1.MyClass() '''生成MyClass实例'''  
  19. x.te()  
  20. print x.cl  
  21. import moa ''''导入另外一个模块'''  
  22. print moa.__file__  
  23. print moa.__name__  
  24. '''try catch,捕捉异常'''  
  25. try:  
  26. print "---------------"+moa.aaa(1)  
  27. except:  
  28. print "Error"  
  29. finally:  
  30. print "finally"  
  31. print moa.aaa(1) 

在 Python 中的 import 就像 Perl 中的 require 。import 一个 Python 模块后,您就可以使用 module .function 来访问它的函数;require 一个 Perl 模块后,您就可以使用 module ::function 来访问它的函数。

相关内容

    暂无相关文章

评论关闭