blob: 46702cd5a621a39c06e31fb6c57cd678aed91683 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
Ask why SyntaxError: because a dict is not hashable!
from oopp import customized
class Customizable(object):
"""Classes inhering from 'Customizable' have a 'with' method acting as
an object modifier"""
def __getitem__(self,**kw):
print kw
with=customized
With=classmethod(customized)
class __metaclass__(type):
def __getitem__(cls,kw=None):
print kw
c=Customizable()
c.with(a='a')
print c.a
Customizable.With(b='b')
#Customizable[a='b']
print c.b
print c[kw='a'] # SyntaxError: invalid syntax
def f(kw='b'): print kw
f(kw='a') # works
|