Pythond类如何进行相关的应用呢?这个问题需要我们不断的学习。下面我们就来介绍下Pythond类的函数编程。只有不断的学习才能更好的使用。Python属于函数是编程。
Python代码
- '''''
- Created on 2009-11-18
- @author: Administrator
- '''
- class MyClass(object):
- '''''
- classdocs
- '''
- cl = [1,2,"5"]
- def __init__(selfparams):
- '''''
- Constructor
- '''
- print "Constructor,..."
- def te(self):
- print "a"
- '''
- Created on 2009-11-18
- @author: Administrator
- '''
- class MyClass(object):
- '''
- classdocs
- '''
- cl = [1,2,"5"]
- def __init__(selfparams):
- '''
- Constructor
- '''
- print "Constructor,..."
- def te(self):
- print "a"
Python代码
- import Class1 '''''导入Class1.py文件'''
- x = Class1.MyClass() '''''生成MyClass实例'''
- x.te()
- print x.cl
- import moa ''''''导入另外一个模块'''
- print moa.__file__
- print moa.__name__
- '''''try catch,捕捉异常'''
- try:
- print "---------------"+moa.aaa(1)
- except:
- print "Error"
- finally:
- print "finally"
- print moa.aaa(1)
- m = moa.M()
- import Class1 '''导入Class1.py文件'''
- x = Class1.MyClass() '''生成MyClass实例'''
- x.te()
- print x.cl
- import moa ''''导入另外一个模块'''
- print moa.__file__
- print moa.__name__
- '''try catch,捕捉异常'''
- try:
- print "---------------"+moa.aaa(1)
- except:
- print "Error"
- finally:
- print "finally"
- print moa.aaa(1)
在 Python 中的 import 就像 Perl 中的 require 。import 一个 Python 模块后,您就可以使用 module .function 来访问它的函数;require 一个 Perl 模块后,您就可以使用 module ::function 来访问它的函数。
【编辑推荐】