Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.3 kB
3
Indexable
Never
#----------------------------CONSTRUCTORS-----------------------------------------
# class Person:
#     name="Ansh"
#     occupation="Product Manager"
#     def __init__(self,n,o):
#         print("Chut ka chakkar, maut se takkar")
#         self.name=n
#         self.occupation=o
#     def info(self):
#         print(f"{self.name} is {self.occupation}")
        
# a=Person("Ansh","PM")
# b=Person("Divya","Scientist")
# a.info()
# b.info()
# # c=Person(1,2,3)    c goes as self argument so this will give an error since 4 arguments are being passed instead of 3
   
   
   
#----------------------------DECORATORS-----------------------------------------
'''
def greet(fx):
  def mfx(*args, **kwargs):
    print("Good Morning")
    fx(*args, **kwargs)
    print("Thanks for using this function")
  return mfx

@greet
def hello():
  print("Hello world")

@greet
def add(a, b):
  print(a+b)
  
# greet(hello)()
hello()
# greet(add)(1, 2)
add(1, 2)

import logging

def log_function_call(func):
    def decorated(*args, **kwargs):
        logging.info(f"Calling {func.__name__} with args={args}, kwargs={kwargs}")
        result = func(*args, **kwargs)
        logging.info(f"{func.__name__} returned {result}")
        return result
    return decorated

@log_function_call
def my_function(a, b):
    return a + b
'''

 
Leave a Comment