<jupyter_start><jupyter_text>https://www.datacamp.com/community/tutorials/decorators-python?utm_source=adwords_ppc&utm_campaignid=1455363063&utm_adgroupid=65083631748&utm_device=c&utm_keyword=&utm_matchtype=b&utm_network=g&utm_adpostion=&utm_creative=278443377095&utm_targetid=aud-299261629574:dsa-429603003980&utm_loc_interest_ms=&utm_loc_physical_ms=1010040&gclid=Cj0KCQjwpf2IBhDkARIsAGVo0D2gcchFA2rGwxbmEj5olQI1oTeNWPxQu7q0kmM_nKvY0uJORLfltqUaAr2OEALw_wcB<jupyter_code>def plus_one(number):
    return number + 1
add_one = plus_one
add_one
add_one(5)
def plus_one(number):
    def add_one(number):
        return number + 1

    result = add_one(number)
    return result
plus_one(4)
#Functions as parameters and functions returning functions. 
def plus_one(number):
    return number + 1

def function_call(function):
    number_to_add = 5
    return function(number_to_add)
function_call(plus_one)
#Functions inside functions
def hello_function():
    def say_hi():
        return "Hi"
    return say_hi
hello = hello_function()
hello()
#Python allows a nested function to access the outer scope of the enclosing function. This is known as closure. 
def print_message(message):
    "Enclosong Function"
    def message_sender():
        "Nested Function"
        print(message)
    
    message_sender()
print_message("Some message")
def uppercase_decorator(function):
    def wrapper():
        func = function()
        make_uppercase = func.upper()
        return make_uppercase

    return wrapper
def say_hi():
    return 'hello there'
decorate = uppercase_decorator(say_hi)
decorate()
#We are decorating the function say_hi with the uppercase_decorator function
@uppercase_decorator
def say_hi():
    return 'hello there'
say_hi()
def split_string(function):
    def wrapper():
        func = function()#function say_hi is called without decorators applied.  
        print(func)
        splitted_string = func.split()
        return splitted_string

    return wrapper
@split_string
@uppercase_decorator
def say_hi():
    return 'hello there'
say_hi()
import functools

def uppercase_decorator(func):
    @functools.wraps(func)
    def wrapper():
        return func().upper()
    return wrapper
@uppercase_decorator
def say_hi():
    "This will say hi"
    return 'hello there'

say_hi()
say_hi.__doc__<jupyter_output><empty_output><jupyter_text>https://www.python-course.eu/python3_decorators.php<jupyter_code>def greeting_func_gen(lang):
    def customized_greeting(name):
        "This is the wrapper!"
        if lang == "de":   # German
            phrase = "Guten Morgen "
        elif lang == "fr": # French
            phrase = "Bonjour "
        elif lang == "it": # Italian
            phrase = "Buongiorno "
        elif lang == "tr": # Turkish
            phrase = "Günaydın "
        elif lang == "gr": # Greek
            phrase = "Καλημερα "
        else:
            phrase = "Hi "
        return phrase + name + "!"
    return customized_greeting
say_hi = greeting_func_gen("de")
print(say_hi)
print(say_hi("Beto")) 
say_hi.__name__
say_hi.__doc__<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09462504023173479, 'fraction_numerical': 0.026392018023817188, 'mean_word_length': 3.8260869565217392, 'pattern_counts': {'":': 5, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '164152', 'license': 'MIT', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1050, 'n_words': 224, 'path': 'NLP/Decorators.ipynb', 'repo_name': 'robretoarenal/ArenalInt', 'size': '3107'}