Pythond類在函數中的編程方法
作者:佚名
Pythond類有很廣泛的應用范圍,在很長時間的應用中有不少的問題需要我們進行學習。下面我們就詳細的看看相關的技術知識。
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 來訪問它的函數。
【編輯推薦】
責任編輯:張浩
來源:
博客園