Hey Guys,
Please help with understanding decorators better. For the below program, I’m expecting output like
<i><b>Test</b></i>.
Instead I’m getting this, with tag order changed.
<b><i>Test</i></b>
This is my code. Just doing to understand decorators better.
def make_bold(inp_func): def bold_wrapper(inp_str): return inp_func('<b>' + inp_str + '</b>') return bold_wrapper def make_italic(inp_func): def italic_wrapper(inp_str): return inp_func('<i>' + inp_str + '</i>') return italic_wrapper @make_italic @make_bold def return_text(inp_str): return inp_str output = return_text("Test") print(output)
submitted by /u/Aguerooooo32
[link] [comments]
r/learnpython Hey Guys, Please help with understanding decorators better. For the below program, I’m expecting output like <i><b>Test</b></i>. Instead I’m getting this, with tag order changed. <b><i>Test</i></b> This is my code. Just doing to understand decorators better. def make_bold(inp_func): def bold_wrapper(inp_str): return inp_func(‘<b>’ + inp_str + ‘</b>’) return bold_wrapper def make_italic(inp_func): def italic_wrapper(inp_str): return inp_func(‘<i>’ + inp_str + ‘</i>’) return italic_wrapper @make_italic @make_bold def return_text(inp_str): return inp_str output = return_text(“Test”) print(output) submitted by /u/Aguerooooo32 [link] [comments]
Hey Guys,
Please help with understanding decorators better. For the below program, I’m expecting output like
<i><b>Test</b></i>.
Instead I’m getting this, with tag order changed.
<b><i>Test</i></b>
This is my code. Just doing to understand decorators better.
def make_bold(inp_func): def bold_wrapper(inp_str): return inp_func('<b>' + inp_str + '</b>') return bold_wrapper def make_italic(inp_func): def italic_wrapper(inp_str): return inp_func('<i>' + inp_str + '</i>') return italic_wrapper @make_italic @make_bold def return_text(inp_str): return inp_str output = return_text("Test") print(output)
submitted by /u/Aguerooooo32
[link] [comments]