Zanurkuj w Pythonie/Klasa opakowująca UserDict: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
Sasek (dyskusja | edycje)
poprawa formatowania (wcześniej tłumaczenie)
Sasek (dyskusja | edycje)
Nie podano opisu zmian
Linia 9:
 
 
class UserDict: <font color=red>#(1)</font>
def __init__(self, dict=None): <font color=red>#(2)</font>
self.data = {} <font color=red>#(3)</font>
if dict is not None: self.update(dict) <font color=red>#(4) (5)</font>
 
# Klasa <tt>UserDict</tt> jest klasą bazową, nie dziedziczy nic z innych klas.
Linia 28:
'''Przykład 5.10. Standartowe metody klasy <tt>UserDict</tt>'''
 
def clear(self): self.data.clear() <font color=red>#(1)</font>
def copy(self): <font color=red>#(2)</font>
if self.__class__ is UserDict: <font color=red>#(3)</font>
return UserDict(self.data)
import copy <font color=red>#(4)</font>
return copy.copy(self)
def keys(self): return self.data.keys() <font color=red>#(5)</font>
def items(self): return self.data.items()
def values(self): return self.data.values()