Python Forum
accessing a second level nested function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
accessing a second level nested function
#1
def html_tag( tag ):

    def body( msg ):
        print( "hi! :", msg )

        def inn_body( msg1 ):
            print( "hola: ", msg1 )
     return inn_body

    return body
h1 = html_tag( "h1" )
h1( "varshini" )
h1( "subiksha" )
/// How do i access the inn_body()?
Reply
#2
def html_tag(tag):

    def body(msg):
        print("hi! :", msg)

        def inn_body(msg1):
            print("hola: ", msg1)

        return inn_body

    return body


h1 = html_tag("h1")
h1("varshini")
h1("subiksha")('inn_body')
Output:
hi! : varshini hi! : subiksha hola: inn_body
Reply
#3
I was going to (ok, did) ask why would you want to do such a thing. Is it to allow writing code like that used in Yoriz' example? Looks confusing to me.
Reply
#4
(Aug-09-2020, 03:40 PM)deanhystad Wrote: I was going to (ok, did) ask why would you want to do such a thing. Is it to allow writing code like that used in Yoriz' example? Looks confusing to me.
No, I was getting a hang of closures concept in python and I wanted to know on how to access a nested fuction using the closure method.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  nested function return MHGhonaim 2 562 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  return vs. print in nested function example Mark17 4 1,674 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  Exit function from nested function based on user input Turtle 5 2,858 Oct-10-2021, 12:55 AM
Last Post: Turtle
Question Stopping a parent function from a nested function? wallgraffiti 1 3,620 May-02-2021, 12:21 PM
Last Post: Gribouillis
  Nested function problem chipx 8 3,414 Oct-21-2020, 11:56 PM
Last Post: jefsummers
  Passing argument from top-level function to embedded function JaneTan 2 2,204 Oct-15-2020, 03:50 PM
Last Post: deanhystad
  How to make this function general to create binary numbers? (many nested for loops) dospina 4 4,332 Jun-24-2020, 04:05 AM
Last Post: deanhystad
  Nested Recursive Function not Returning Etotheitau 2 2,218 May-09-2020, 06:09 PM
Last Post: Etotheitau
  Accessing method as function object ClassicalSoul 2 1,975 Feb-14-2020, 09:31 PM
Last Post: wavic
  Repair function for a nested database Alfalfa 1 2,202 Jan-25-2019, 12:08 AM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020