python-CSD-kursu/python-temel/callable.nesne.py
2023-08-06 17:17:39 +03:00

21 lines
389 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Mample:
def __init__(self, cls):
self.cls = cls
def __call__(self, *args, **kwargs):
print('Her Sample nesnesi yaratıldığında araya giren kod')
return self.cls(*args, **kwargs)
def foo(cls):
return Mample(cls)
@foo
class Sample:
def __init__(self, a):
self.a = a
def bar(self):
print('bar')
s = Sample(10)
s.bar()