1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| >>> class maClasse:
... def __init__(self, random=random.random):
... print(random())
...
>>> maClasse()
0.328800963927
<__main__.maClasse instance at 0xb787bc6c>
>>> class maClasse:
... def __init__(self, random=random.random):
... r = random.random()
... print(r)
...
>>> maClasse()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
AttributeError: 'builtin_function_or_method' object has no attribute 'random'
>>> maClasse(lambda: 0.5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
AttributeError: 'function' object has no attribute 'random' |
Partager