亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python??序列化反序列化和異常處理的問題小結(jié)

 更新時(shí)間:2022年12月23日 15:36:18   作者:南極找南  
這篇文章主要介紹了Python?序列化反序列化和異常處理,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1.迭代器

迭代是訪問集合元素的一種方式。迭代器是一個(gè)可以記住遍歷的位置的對(duì)象。迭代器對(duì)象從集合的第一個(gè)元素開始訪問,直到所有的元素被訪問完結(jié)束。迭代器只能往前不會(huì)后退。

1.1 可迭代對(duì)象

我們已經(jīng)知道可以對(duì)list、tuple、str等類型的數(shù)據(jù)使用for...in...的循環(huán)語法從其中依次拿到數(shù)據(jù)進(jìn)行使用,我們把這樣的過程稱為遍歷,也叫迭代

但是,是否所有的數(shù)據(jù)類型都可以放到for...in...的語句中,然后讓for...in...每次從中取出一條數(shù)據(jù)供我們使用,即供我們迭代嗎?

>>> for i in 100:
 ...     print(i)
 ...
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
 TypeError: 'int' object is not iterable
 >>>
# int整型不是iterable,即int整型不是可以迭代的

我們把可以通過for...in...這類語句迭代讀取一條數(shù)據(jù)供我們使用的對(duì)象稱之為可迭代對(duì)象(Iterable)。

1.2 如何判斷一個(gè)對(duì)象是否可以迭代

可以使用 isinstance() 判斷一個(gè)對(duì)象是否是 Iterable 對(duì)象:

 In [50]: from collections import Iterable
 
 In [51]: isinstance([], Iterable)
 Out[51]: True
 
 In [52]: isinstance({}, Iterable)
 Out[52]: True
 
 In [53]: isinstance('abc', Iterable)
 Out[53]: True
 
 In [54]: isinstance(mylist, Iterable)
 Out[54]: False
 
 In [55]: isinstance(100, Iterable)
 Out[55]: False

1.3 可迭代對(duì)象的本質(zhì)

我們分析對(duì)可迭代對(duì)象進(jìn)行迭代使用的過程,發(fā)現(xiàn)每迭代一次(即在for...in...中每循環(huán)一次)都會(huì)返回對(duì)象中的下一條數(shù)據(jù),一直向后讀取數(shù)據(jù)直到迭代了所有數(shù)據(jù)后結(jié)束。那么,在這個(gè)過程中就應(yīng)該有一個(gè)“人”去記錄每次訪問到了第幾條數(shù)據(jù),以便每次迭代都可以返回下一條數(shù)據(jù)。我們把這個(gè)能幫助我們進(jìn)行數(shù)據(jù)迭代的“人”稱為迭代器(Iterator)。

可迭代對(duì)象的本質(zhì)就是可以向我們提供一個(gè)這樣的中間“人”即迭代器幫助我們對(duì)其進(jìn)行迭代遍歷使用。

可迭代對(duì)象通過__iter__方法向我們提供一個(gè)迭代器,我們在迭代一個(gè)可迭代對(duì)象的時(shí)候,實(shí)際上就是先獲取該對(duì)象提供的一個(gè)迭代器,然后通過這個(gè)迭代器來依次獲取對(duì)象中的每一個(gè)數(shù)據(jù).

那么也就是說,一個(gè)具備了__iter__方法的對(duì)象,就是一個(gè)可迭代對(duì)象。

 from collections.abc import Iterable
 class Demo(object):
     def __init__(self, n):
         self.n = n
         self.current = 0
     def __iter__(self):
         pass
 
 demo = Demo(10)
 print(isinstance(demo, Iterable))  # True
 
 for d in demo:   # 重寫了 __iter__ 方法以后,demo就是一個(gè)一個(gè)可迭代對(duì)象了,可以放在for...in的后面
     print(d)
 
 # 此時(shí)再使用for...in循環(huán)遍歷,會(huì)提示 TypeError: iter() returned non-iterator of type 'NoneType'
 # 這是因?yàn)?,一個(gè)可迭代對(duì)象如果想要被for...in循環(huán),它必須要有一個(gè)迭代器

1.4 迭代器Iterator

通過上面的分析,我們已經(jīng)知道,迭代器是用來幫助我們記錄每次迭代訪問到的位置,當(dāng)我們對(duì)迭代器使用next()函數(shù)的時(shí)候,迭代器會(huì)向我們返回它所記錄位置的下一個(gè)位置的數(shù)據(jù)。實(shí)際上,在使用next()函數(shù)的時(shí)候,調(diào)用的就是迭代器對(duì)象的__next__方法(Python3中是對(duì)象的__next__方法,Python2中是對(duì)象的next()方法)。所以,我們要想構(gòu)造一個(gè)迭代器,就要實(shí)現(xiàn)它的*next*方法。但這還不夠,python要求迭代器本身也是可迭代的,所以我們還要為迭代器實(shí)現(xiàn)__iter__方法,而__iter__方法要返回一個(gè)迭代器,迭代器自身正是一個(gè)迭代器,所以迭代器的__iter__方法返回自身即可。

一個(gè)實(shí)現(xiàn)了*iter*方法和*next*方法的對(duì)象,就是迭代器。

 class MyIterator(object):
     def __init__(self, n):
         self.n = n
         self.current = 0
 
     # 自定義迭代器需要重寫__iter__和__next__方法
     def __iter__(self):
         return self
 
     def __next__(self):
         if self.current < self.n:
             value = self.current
             self.current += 1
             return value
         else:
             raise StopIteration
 
 my_it = MyIterator(10)
 
 for i in my_it:    # 迭代器重寫了__iter__方法,它本身也是一個(gè)可迭代對(duì)象
     print(i)

1.5 如何判斷一個(gè)對(duì)象是否迭代器

調(diào)用一個(gè)對(duì)象的__iter__方法,或者調(diào)用iter()內(nèi)置函數(shù),可以獲取到一個(gè)可迭代對(duì)象的迭代器。

 names = ['hello', 'good', 'yes']
 print(names.__iter__())  # 調(diào)用對(duì)象的__iter__()方法
 print(iter(names))  # 調(diào)用iter()內(nèi)置函數(shù)

可以使用 isinstance() 判斷一個(gè)對(duì)象是否是 Iterator 對(duì)象:

 from collections.abc import Iterator
 names = ['hello', 'good', 'yes']
 print(isinstance(iter(names), Iterator))

1.6 for...in...循環(huán)的本質(zhì)

for item in Iterable 循環(huán)的本質(zhì)就是先通過iter()函數(shù)獲取可迭代對(duì)象Iterable的迭代器,然后對(duì)獲取到的迭代器不斷調(diào)用next()方法來獲取下一個(gè)值并將其賦值給item,當(dāng)遇到StopIteration的異常后循環(huán)結(jié)束。

1.7 迭代器的應(yīng)用場景

我們發(fā)現(xiàn)迭代器最核心的功能就是可以通過next()函數(shù)的調(diào)用來返回下一個(gè)數(shù)據(jù)值。如果每次返回的數(shù)據(jù)值不是在一個(gè)已有的數(shù)據(jù)集合中讀取的,而是通過程序按照一定的規(guī)律計(jì)算生成的,那么也就意味著可以不用再依賴一個(gè)已有的數(shù)據(jù)集合,也就是說不用再將所有要迭代的數(shù)據(jù)都一次性緩存下來供后續(xù)依次讀取,這樣可以節(jié)省大量的存儲(chǔ)(內(nèi)存)空間。

舉個(gè)例子,比如,數(shù)學(xué)中有個(gè)著名的斐波拉契數(shù)列(Fibonacci),數(shù)列中第一個(gè)數(shù)為0,第二個(gè)數(shù)為1,其后的每一個(gè)數(shù)都可由前兩個(gè)數(shù)相加得到:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

現(xiàn)在我們想要通過for...in...循環(huán)來遍歷迭代斐波那契數(shù)列中的前n個(gè)數(shù)。那么這個(gè)斐波那契數(shù)列我們就可以用迭代器來實(shí)現(xiàn),每次迭代都通過數(shù)學(xué)計(jì)算來生成下一個(gè)數(shù)。

 class FibIterator(object):
     """斐波那契數(shù)列迭代器"""
     def __init__(self, n):
         """
        :param n: int, 指明生成數(shù)列的前n個(gè)數(shù)
        """
         self.n = n
         # current用來保存當(dāng)前生成到數(shù)列中的第幾個(gè)數(shù)了
         self.current = 0
         # num1用來保存前前一個(gè)數(shù),初始值為數(shù)列中的第一個(gè)數(shù)0
         self.num1 = 0
         # num2用來保存前一個(gè)數(shù),初始值為數(shù)列中的第二個(gè)數(shù)1
         self.num2 = 1
 
     def __next__(self):
         """被next()函數(shù)調(diào)用來獲取下一個(gè)數(shù)"""
         if self.current < self.n:
             num = self.num1
             self.num1, self.num2 = self.num2, self.num1+self.num2
             self.current += 1
             return num
         else:
             raise StopIteration
 
     def __iter__(self):
         """迭代器的__iter__返回自身即可"""
         return self
 
 
 if __name__ == '__main__':
     fib = FibIterator(10)
     for num in fib:
         print(num, end=" ")

2.生成器

利用迭代器,我們可以在每次迭代獲取數(shù)據(jù)(通過next()方法)時(shí)按照特定的規(guī)律進(jìn)行生成。但是我們在實(shí)現(xiàn)一個(gè)迭代器時(shí),關(guān)于當(dāng)前迭代到的狀態(tài)需要我們自己記錄,進(jìn)而才能根據(jù)當(dāng)前狀態(tài)生成下一個(gè)數(shù)據(jù)。為了達(dá)到記錄當(dāng)前狀態(tài),并配合next()函數(shù)進(jìn)行迭代使用,我們可以采用更簡便的語法,即生成器(generator)。生成器是一類特殊的迭代器

2.1 創(chuàng)建生成器方法1

要?jiǎng)?chuàng)建一個(gè)生成器,有很多種方法。第一種方法很簡單,只要把一個(gè)列表生成式的 [ ] 改成 ( )

 In [15]: L = [ x*2 for x in range(5)]
 
 In [16]: L
 Out[16]: [0, 2, 4, 6, 8]
 
 In [17]: G = ( x*2 for x in range(5))
 
 In [18]: G
 Out[18]: <generator object <genexpr> at 0x7f626c132db0>
 
 In [19]:

創(chuàng)建 L 和 G 的區(qū)別僅在于最外層的 [ ] 和 ( ) , L 是一個(gè)列表,而 G 是一個(gè)生成器。我們可以直接打印出列表L的每一個(gè)元素,而對(duì)于生成器G,我們可以按照迭代器的使用方法來使用,即可以通過next()函數(shù)、for循環(huán)、list()等方法使用。

 
In [19]: next(G)
Out[19]: 0
 
In [20]: next(G)
Out[20]: 2
 
In [21]: next(G)
Out[21]: 4
 
In [22]: next(G)
Out[22]: 6
 
In [23]: next(G)
Out[23]: 8
 
In [24]: next(G)
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
<ipython-input-24-380e167d6934> in <module>()
----> 1 next(G)
 
StopIteration:
 
In [25]:
In [26]: G = ( x*2 for x in range(5))
 
In [27]: for x in G:
   ....:     print(x)
   ....:     
0
2
4
6
8
 
In [28]:

2.2 創(chuàng)建生成器方法2

generator非常強(qiáng)大。如果推算的算法比較復(fù)雜,用類似列表生成式的 for 循環(huán)無法實(shí)現(xiàn)的時(shí)候,還可以用函數(shù)來實(shí)現(xiàn)。

我們?nèi)匀挥蒙弦还?jié)提到的斐波那契數(shù)列來舉例,回想我們在上一節(jié)用迭代器的實(shí)現(xiàn)方式:

class FibIterator(object):
    """斐波那契數(shù)列迭代器"""
    def __init__(self, n):
        """
        :param n: int, 指明生成數(shù)列的前n個(gè)數(shù)
        """
        self.n = n
        # current用來保存當(dāng)前生成到數(shù)列中的第幾個(gè)數(shù)了
        self.current = 0
        # num1用來保存前前一個(gè)數(shù),初始值為數(shù)列中的第一個(gè)數(shù)0
        self.num1 = 0
        # num2用來保存前一個(gè)數(shù),初始值為數(shù)列中的第二個(gè)數(shù)1
        self.num2 = 1
 
    def __next__(self):
        """被next()函數(shù)調(diào)用來獲取下一個(gè)數(shù)"""
        if self.current < self.n:
            num = self.num1
            self.num1, self.num2 = self.num2, self.num1+self.num2
            self.current += 1
            return num
        else:
            raise StopIteration
 
    def __iter__(self):
        """迭代器的__iter__返回自身即可"""
        return self

注意,在用迭代器實(shí)現(xiàn)的方式中,我們要借助幾個(gè)變量(n、current、num1、num2)來保存迭代的狀態(tài)。現(xiàn)在我們用生成器來實(shí)現(xiàn)一下。

 
In [30]: def fib(n):
   ....:     current = 0
   ....:     num1, num2 = 0, 1
   ....:     while current < n:
   ....:         yield num1
   ....:         num1, num2 = num2, num1+num2
   ....:         current += 1
   ....:     return 'done'
   ....:
 
In [31]: F = fib(5)
 
In [32]: next(F)
Out[32]: 1
 
In [33]: next(F)
Out[33]: 1
 
In [34]: next(F)
Out[34]: 2
 
In [35]: next(F)
Out[35]: 3
 
In [36]: next(F)
Out[36]: 5
 
In [37]: next(F)
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
<ipython-input-37-8c2b02b4361a> in <module>()
----> 1 next(F)
 
StopIteration: done

在使用生成器實(shí)現(xiàn)的方式中,我們將原本在迭代器__next__方法中實(shí)現(xiàn)的基本邏輯放到一個(gè)函數(shù)中來實(shí)現(xiàn),但是將每次迭代返回?cái)?shù)值的return換成了yield,此時(shí)新定義的函數(shù)便不再是函數(shù),而是一個(gè)生成器了。簡單來說:只要在def中有yield關(guān)鍵字的 就稱為 生成器

此時(shí)按照調(diào)用函數(shù)的方式( 案例中為F = fib(5) )使用生成器就不再是執(zhí)行函數(shù)體了,而是會(huì)返回一個(gè)生成器對(duì)象( 案例中為F ),然后就可以按照使用迭代器的方式來使用生成器了。

In [38]: for n in fib(5):
   ....:     print(n)
   ....:     
1
1
2
3
5
 
In [39]:

但是用for循環(huán)調(diào)用generator時(shí),發(fā)現(xiàn)拿不到generator的return語句的返回值。如果想要拿到返回值,必須捕獲StopIteration錯(cuò)誤,返回值包含在StopIteration的value中:

In [39]: g = fib(5)
 
In [40]: while True:
   ....:     try:
   ....:         x = next(g)
   ....:         print("value:%d"%x)      
   ....:     except StopIteration as e:
   ....:         print("生成器返回值:%s"%e.value)
   ....:         break
   ....:     
value:1
value:1
value:2
value:3
value:5
生成器返回值:done
 
In [41]:

總結(jié):

  • 使用了yield關(guān)鍵字的函數(shù)不再是函數(shù),而是生成器。(使用了yield的函數(shù)就是生成器)
  • yield關(guān)鍵字有兩點(diǎn)作用:
  • 保存當(dāng)前運(yùn)行狀態(tài)(斷點(diǎn)),然后暫停執(zhí)行,即將生成器(函數(shù))掛起
  • 將yield關(guān)鍵字后面表達(dá)式的值作為返回值返回,此時(shí)可以理解為起到了return的作用
  • 可以使用next()函數(shù)讓生成器從斷點(diǎn)處繼續(xù)執(zhí)行,即喚醒生成器(函數(shù))
  • Python3中的生成器可以使用return返回最終運(yùn)行的返回值,而Python2中的生成器不允許使用return返回一個(gè)返回值(即可以使用return從生成器中退出,但return后不能有任何表達(dá)式)。

2.3 使用send喚醒

我們除了可以使用next()函數(shù)來喚醒生成器繼續(xù)執(zhí)行外,還可以使用send()函數(shù)來喚醒執(zhí)行。使用send()函數(shù)的一個(gè)好處是可以在喚醒的同時(shí)向斷點(diǎn)處傳入一個(gè)附加數(shù)據(jù)。

例子:執(zhí)行到y(tǒng)ield時(shí),gen函數(shù)作用暫時(shí)保存,返回i的值; temp接收下次c.send("python"),send發(fā)送過來的值,c.next()等價(jià)c.send(None)

In [10]: def gen():
   ....:     i = 0
   ....:     while i<5:
   ....:         temp = yield i
   ....:         print(temp)
   ....:         i+=1
   ....:

使用send

In [43]: f = gen()
 
In [44]: next(f)
Out[44]: 0
 
In [45]: f.send('haha')
haha
Out[45]: 1
 
In [46]: next(f)
None
Out[46]: 2
 
In [47]: f.send('haha')
haha
Out[47]: 3
 
In [48]:

使用next函數(shù)

In [18]: f = gen()
 
In [19]: f.__next__()
Out[19]: 0
 
In [20]: f.__next__()
None
Out[20]: 1
 
In [21]: f.__next__()
None
Out[21]: 2
 
In [22]: f.__next__()
None
Out[22]: 3
 
In [23]: f.__next__()
None
Out[23]: 4
 
In [24]: f.__next__()
None
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
<ipython-input-24-39ec527346a9> in <module>()
----> 1 f.__next__()
 
StopIteration:

使用__next__()方法(不常使用)

In [18]: f = gen()
 
In [19]: f.__next__()
Out[19]: 0
 
In [20]: f.__next__()
None
Out[20]: 1
 
In [21]: f.__next__()
None
Out[21]: 2
 
In [22]: f.__next__()
None
Out[22]: 3
 
In [23]: f.__next__()
None
Out[23]: 4
 
In [24]: f.__next__()
None
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
<ipython-input-24-39ec527346a9> in <module>()
----> 1 f.__next__()
 
StopIteration:

3.property屬性的使用

property屬性是一種用起來像是實(shí)例屬性一樣的特殊屬性,可以對(duì)應(yīng)于某個(gè)方法。

class Foo:
    def func(self):
        pass
 
    # 定義property屬性
    @property
    def prop(self):
        pass
 
# ############### 調(diào)用 ###############
foo_obj = Foo()
foo_obj.func()  # 調(diào)用實(shí)例方法
foo_obj.prop  # 調(diào)用property屬性

property屬性的定義和調(diào)用要注意一下幾點(diǎn):

  • 定義時(shí),在實(shí)例方法的基礎(chǔ)上添加 @property 裝飾器;并且僅有一個(gè)self參數(shù)
  • 調(diào)用時(shí),無需括號(hào)
  方法:foo_obj.func()
  property屬性:foo_obj.prop

簡單的實(shí)例

對(duì)于京東商城中顯示電腦主機(jī)的列表頁面,每次請求不可能把數(shù)據(jù)庫中的所有內(nèi)容都顯示到頁面上,而是通過分頁的功能局部顯示,所以在向數(shù)據(jù)庫中請求數(shù)據(jù)時(shí)就要顯示的指定獲取從第m條到第n條的所有數(shù)據(jù) 這個(gè)分頁的功能包括:

  • 根據(jù)用戶請求的當(dāng)前頁和總數(shù)據(jù)條數(shù)計(jì)算出 m 和 n
  • 根據(jù)m 和 n 去數(shù)據(jù)庫中請求數(shù)據(jù)
# ############### 定義 ###############
class Pager:
    def __init__(self, current_page):
        # 用戶當(dāng)前請求的頁碼(第一頁、第二頁...)
        self.current_page = current_page
        # 每頁默認(rèn)顯示10條數(shù)據(jù)
        self.per_items = 10 
 
    @property
    def start(self):
        val = (self.current_page - 1) * self.per_items
        return val
 
    @property
    def end(self):
        val = self.current_page * self.per_items
        return val
 
# ############### 調(diào)用 ###############
p = Pager(1)
p.start  # 就是起始值,即:m
p.end  # 就是結(jié)束值,即:n

從上述可見

Python的property屬性的功能是:property屬性內(nèi)部進(jìn)行一系列的邏輯計(jì)算,最終將計(jì)算結(jié)果返回。

3.1 property屬性的兩種方式

  • 裝飾器 即:在方法上應(yīng)用裝飾器
  • 類屬性 即:在類中定義值為property對(duì)象的類屬性

3.1.1 裝飾器

  • 在類的實(shí)例方法上應(yīng)用@property裝飾器

Python中的類有經(jīng)典類和新式類,新式類的屬性比經(jīng)典類的屬性豐富。( 如果類繼object,那么該類是新式類 )

經(jīng)典類的實(shí)現(xiàn):

class Goods:
    @property
    def price(self):
        return "laowang"
 
obj = Goods()
result = obj.price  # 自動(dòng)執(zhí)行 @property 修飾的 price 方法,并獲取方法的返回值
print(result)

新式類的實(shí)現(xiàn):

class Goods:
    """
    只有在python3中才有@xxx.setter  @xxx.deleter
    """
    def __init__(self):
        # 原價(jià)
        self.original_price = 100
        # 折扣
        self.discount = 0.8
 
    @property
    def price(self):
        new_price = self.original_price * self.discount
        return new_price
 
    @price.setter
    def price(self, value):
        self.original_price = value
 
    @price.deleter
    def price(self):
        del self.original_price
obj = Goods()
obj.price          # 獲取商品價(jià)格
obj.price = 200    # 修改商品原價(jià)
del obj.price      # 刪除商品原價(jià)

總結(jié):

  • 經(jīng)典類中的屬性只有一種訪問方式,其對(duì)應(yīng)被 @property 修飾的方法
  • 新式類中的屬性有三種訪問方式,并分別對(duì)應(yīng)了三個(gè)被@property、@方法名.setter、@方法名.deleter修飾的方法

3.1.2 類屬性方式

當(dāng)使用類屬性的方式創(chuàng)建property屬性時(shí),經(jīng)典類和新式類無區(qū)別。

class Foo:
    def get_bar(self):
        return 'laowang'
    BAR = property(get_bar)
 
obj = Foo()
reuslt = obj.BAR  # 自動(dòng)調(diào)用get_bar方法,并獲取方法的返回值
print(reuslt)

property方法中有個(gè)四個(gè)參數(shù)

  • 第一個(gè)參數(shù)是方法名,調(diào)用 對(duì)象.屬性 時(shí)自動(dòng)觸發(fā)執(zhí)行方法
  • 第二個(gè)參數(shù)是方法名,調(diào)用 對(duì)象.屬性 = XXX 時(shí)自動(dòng)觸發(fā)執(zhí)行方法
  • 第三個(gè)參數(shù)是方法名,調(diào)用 del 對(duì)象.屬性 時(shí)自動(dòng)觸發(fā)執(zhí)行方法
  • 第四個(gè)參數(shù)是字符串,調(diào)用 對(duì)象.屬性.doc ,此參數(shù)是該屬性的描述信息
class Foo(object):
    def get_bar(self):
        print("getter...")
        return 'laowang'
 
    def set_bar(self, value): 
        """必須兩個(gè)參數(shù)"""
        print("setter...")
        return 'set value' + value
 
    def del_bar(self):
        print("deleter...")
        return 'laowang'
 
    BAR = property(get_bar, set_bar, del_bar, "description...")
 
obj = Foo()
 
obj.BAR  # 自動(dòng)調(diào)用第一個(gè)參數(shù)中定義的方法:get_bar
obj.BAR = "alex"  # 自動(dòng)調(diào)用第二個(gè)參數(shù)中定義的方法:set_bar方法,并將“alex”當(dāng)作參數(shù)傳入
desc = Foo.BAR.__doc__  # 自動(dòng)獲取第四個(gè)參數(shù)中設(shè)置的值:description...
print(desc)
del obj.BAR  # 自動(dòng)調(diào)用第三個(gè)參數(shù)中定義的方法:del_bar方法

總結(jié):

  • 定義property屬性共有兩種方式,分別是【裝飾器】和【類屬性】,而【裝飾器】方式針對(duì)經(jīng)典類和新式類又有所不同。
  • 通過使用property屬性,能夠簡化調(diào)用者在獲取數(shù)據(jù)的流程。

到此這篇關(guān)于Python  序列化反序列化和異常處理的文章就介紹到這了,更多相關(guān)Python  序列化反序列化內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論