Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my_list = []
- def decorator(func):
- def wrapper(some_item):
- if isinstance(some_item, str):
- result = func(some_item)
- print(f"{some_item} added to the list")
- return result
- else:
- print(f"Error: {some_item} is not a string and won't be added to the list.")
- return None
- return wrapper
- @decorator
- def add_to_list(item):
- my_list.append(item)
- add_to_list("hello")
- add_to_list(123) # not added
- add_to_list("world")
- print(my_list) # ['hello', 'world']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement