Skip to content

Commit 9f24bfe

Browse files
committed
fix last example
1 parent 183d00d commit 9f24bfe

File tree

3 files changed

+47
-41
lines changed

3 files changed

+47
-41
lines changed

decorator.md

+21-18
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ __Result:__
188188
>> type(say_miau) : <class '__main__.CountCalls'>
189189
>> say_miau.__name__ : say_miau
190190
>> say_miau.__doc__ : docstring: print the vocalization of a Felis Catus, also known as cat
191-
>> say_miau.__wrapped__ : <function say_miau at 0x7f865fde8a60>
191+
>> say_miau.__wrapped__ : <function say_miau at 0x7fc95e4d4a60>
192192
```
193193

194194
Attention!
@@ -341,7 +341,7 @@ for idx in range(1, 4):
341341
__Result:__
342342

343343
```
344-
>> LimitCalls function: <function square_me at 0x7f865fdee4c0> max_hits: 3 log_calls: False
344+
>> LimitCalls function: <function square_me at 0x7fc95e4da4c0> max_hits: 3 log_calls: False
345345
>> square_me type: <class '__main__._LimitCalls'>
346346
>> idx: 1
347347
>> call # 1 returns: 4
@@ -447,7 +447,7 @@ __Result:__
447447
>> LimitCalls function: None max_hits: 1 log_calls: True
448448
>> Calling: Foo #call: 1 positional-arguments: keyword-arguments:
449449
>> inside Foo.__init__
450-
>> Return from: Foo #call: 1 return-value: <__main__.Foo object at 0x7f865fde55b0>
450+
>> Return from: Foo #call: 1 return-value: <__main__.Foo object at 0x7fc95e4d15b0>
451451
>> do_something in Foo
452452
```
453453

@@ -614,8 +614,8 @@ for idx in range(1, 5):
614614
__Result:__
615615

616616
```
617-
>> LimitCalls2 _func: <function dec_three_from_me at 0x7f865fdf4940> max_hits: 3 Log_calls: False
618-
>> LimitCalls in nested forward_func_call. func: <function dec_three_from_me at 0x7f865fdf4940>
617+
>> LimitCalls2 _func: <function dec_three_from_me at 0x7fc95e4e0940> max_hits: 3 Log_calls: False
618+
>> LimitCalls in nested forward_func_call. func: <function dec_three_from_me at 0x7fc95e4e0940>
619619
>> type(dec_three_from_me) : <class 'function'>
620620
>> dec_three_from_me.__name__ : dec_three_from_me
621621
>> dec_three_from_me.__doc__ : None
@@ -659,7 +659,7 @@ __Result:__
659659

660660
```
661661
>> LimitCalls2 _func: None max_hits: 2 Log_calls: True
662-
>> LimitCalls in nested forward_func_call. func: <function dec_me at 0x7f865fdf4f70>
662+
>> LimitCalls in nested forward_func_call. func: <function dec_me at 0x7fc95e4e0f70>
663663
>> idx: 1
664664
>> Calling: dec_me #call: 1 positional-arguments: 1 keyword-arguments:
665665
>> Return from: dec_me #call: 1 return-value: 0
@@ -700,7 +700,7 @@ __Result:__
700700
>> LimitCalls in nested forward_func_call. func: <class '__main__.Foo3'>
701701
>> Calling: Foo3 #call: 1 positional-arguments: keyword-arguments:
702702
>> inside Foo3.__init__
703-
>> Return from: Foo3 #call: 1 return-value: <__main__.Foo3 object at 0x7f865fdf6b50>
703+
>> Return from: Foo3 #call: 1 return-value: <__main__.Foo3 object at 0x7fc95e4e1b50>
704704
>> do_something in Foo3
705705
```
706706

@@ -731,9 +731,9 @@ __Result:__
731731

732732
```
733733
>> LimitCalls2 _func: None max_hits: 3 Log_calls: True
734-
>> LimitCalls in nested forward_func_call. func: <function Foo4.do_something at 0x7f865fdf4d30>
734+
>> LimitCalls in nested forward_func_call. func: <function Foo4.do_something at 0x7fc95e4e0d30>
735735
>> inside Foo4.__init__
736-
>> Calling: do_something #call: 1 positional-arguments: <__main__.Foo4 object at 0x7f865fd26970> keyword-arguments:
736+
>> Calling: do_something #call: 1 positional-arguments: <__main__.Foo4 object at 0x7fc95e426970> keyword-arguments:
737737
>> do_something in Foo4
738738
>> Return from: do_something #call: 1 return-value: None
739739
```
@@ -787,8 +787,8 @@ __Result:__
787787

788788
```
789789
>> absolute of a number: 3
790-
>> random number between 0 and 1 0.9421784193905641
791-
>> random number between 0 and 1 0.2758141177857678
790+
>> random number between 0 and 1 0.72300472140728
791+
>> random number between 0 and 1 0.8604189007624241
792792
```
793793

794794
A method that is declared with the @classmthod decorator, here the first parameter is the class object. Note that a method like this doesn't have a self parameter.
@@ -826,7 +826,7 @@ print("color red: ", colour_red , "red:", colour_red.red , "green:", colour_red.
826826
__Result:__
827827

828828
```
829-
>> color red: <__main__.Colour object at 0x7f865fe0afa0> red: 255 green: 0 blue: 0
829+
>> color red: <__main__.Colour object at 0x7fc95e4f6fa0> red: 255 green: 0 blue: 0
830830
```
831831

832832
At first it doesn't make an awfull lot of sense, but lets derive the ColourWithAlphaChannel class from Colour
@@ -857,7 +857,7 @@ print("color red: ", colour_red , "red:", colour_red.red , "green:", colour_red.
857857
__Result:__
858858

859859
```
860-
>> color red: <__main__.ColourWithAlphaChannel object at 0x7f865fde95b0> red: 255 green: 0 blue: 0 alpha: 1.0
860+
>> color red: <__main__.ColourWithAlphaChannel object at 0x7fc95e4d55b0> red: 255 green: 0 blue: 0 alpha: 1.0
861861
```
862862

863863

@@ -1036,30 +1036,33 @@ class Person:
10361036
self.last_name = last_name
10371037
10381038
def __eq__(self, other):
1039-
return (self.first_name, other.first_name) == (self.last_name, other.last_name)
1039+
return (self.first_name, other.last_name) == (self.first_name, other.last_name)
10401040
10411041
def __lt__(self, other):
10421042
return (self.first_name, self.last_name) < (other.first_name, other.last_name)
10431043
1044-
person_a = Person("Jack", "Beean")
1044+
person_a = Person("Jack", "Bean")
10451045
person_b = Person("Patricia", "Donovan")
10461046
10471047
print("person_a.__dict__ : ", person_a.__dict__)
10481048
print("person_b.__dict__ : ", person_b.__dict__)
10491049
1050-
assert not person_a == person_b
1050+
assert person_a == person_b
10511051
assert person_a < person_b
10521052
# the added operators
1053+
assert not person_a != person_b
10531054
assert person_a <= person_b
1055+
assert not person_a > person_b
1056+
assert not person_a >= person_b
10541057
10551058
```
10561059

10571060
__Result:__
10581061

10591062
```
1060-
>> person_a.__dict__ : {'first_name': 'Jack', 'last_name': 'Beean'}
1063+
>> person_a.__dict__ : {'first_name': 'Jack', 'last_name': 'Bean'}
10611064
>> person_b.__dict__ : {'first_name': 'Patricia', 'last_name': 'Donovan'}
10621065
```
10631066

1064-
*** eof .tutorial ***
1067+
*** eof tutorial ***
10651068

decorator.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -693,21 +693,24 @@ def __init__(self, first_name, last_name):
693693
self.last_name = last_name
694694
695695
def __eq__(self, other):
696-
return (self.first_name, other.first_name) == (self.last_name, other.last_name)
696+
return (self.first_name, other.last_name) == (self.first_name, other.last_name)
697697
698698
def __lt__(self, other):
699699
return (self.first_name, self.last_name) < (other.first_name, other.last_name)
700700
701-
person_a = Person("Jack", "Beean")
701+
person_a = Person("Jack", "Bean")
702702
person_b = Person("Patricia", "Donovan")
703703
704704
print("person_a.__dict__ : ", person_a.__dict__)
705705
print("person_b.__dict__ : ", person_b.__dict__)
706706
707-
assert not person_a == person_b
707+
assert person_a == person_b
708708
assert person_a < person_b
709709
# the added operators
710+
assert not person_a != person_b
710711
assert person_a <= person_b
712+
assert not person_a > person_b
713+
assert not person_a >= person_b
711714
""")
712715

713-
print("*** eof .tutorial ***")
716+
print("*** eof tutorial ***")

0 commit comments

Comments
 (0)