Я не понимаю, почему я не могу получить доступ к имени внутренней функции, украшенной внешней функцией?
это вызывает эту ошибку:NameError: имя «inner_text_function» не определено
def outer_wrapper_function(func) -> str:
print(f"This is the outer function: named -|{outer_wrapper_function.__name__}|- and located at -|{outer_wrapper_function}")
print(f" |-->This is the inner function: named -|{func.__name__}|- and located at -|{func}")
textwraped: str = func().upper()
print(f"Text wrapped: {textwraped}")
return textwraped
#Passing a function as argument var_1:
def inner_text_function() -> str:
print(f" |-->This is the inner function: named -|{inner_text_function.__name__}|- and located at -|{inner_text_function}")
textwrap = "this is some texts to be wrapped ****"
print(f"Text un-wrapped: {textwrap}")
return textwrap
text_function = outer_wrapper_function(func = inner_text_function)
print(text_function)
#Now printing the inner_text_function not decorated with @ suntax:
text_function = inner_text_function
print(text_function)
#Passing a function as argument var_2:
@outer_wrapper_function
def inner_text_function(text = "NOW") -> str:
print(f" |-->This is the inner function: named -|{inner_text_function.__name__}|- and located at -|{inner_text_function}")
textwrap = "this is some texts to be wrapped ****".replace('****', text)
print(f"Text un-wrapped: {textwrap}")
return textwrap
#Now printing the inner_text_function alredy decorated with @ suntax:
text_function = inner_text_function
print(text_function, type(inner_text_function))
#it work if i pass the inner function as the var_1 but it raise that error with te var_2. why?
Подробнее здесь: https://stackoverflow.com/questions/788 ... decorators
Почему функция Internal_text_function не определена при использовании декораторов? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Основы функции - Function Function Function, выходящая из INT, более 99 [закрыто]
Anonymous » » в форуме Python - 0 Ответы
- 34 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Приложение Function Function Function не может найти функцию на AWS Lambda
Anonymous » » в форуме JAVA - 0 Ответы
- 1 Просмотры
-
Последнее сообщение Anonymous
-
-
-
NameError: переменная не определена, хотя она определена и работала раньше
Anonymous » » в форуме Python - 0 Ответы
- 54 Просмотры
-
Последнее сообщение Anonymous
-