Python Forum
function defined inside a function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: function defined inside a function (/thread-33611.html)



function defined inside a function - Skaperen - May-11-2021

when defining a function inside a function, even deep functions can access variables all the way to the first function. is there any limit to how far this can be nested and still access every variable all the way and everywhere in between?


RE: function defined inside a function - BashBedlam - May-11-2021

Apparently not. You can extend this and see how far you get Big Grin

a = 1
def one () :
	b = 2
	def two () :
		c = 3
		def three () :
			d = 4
			def four () :
				e = 5
				def five () :
					f = 6
					def six () :
						g = 7
						print (a, b, c, d, e, f, g)
					six ()
				five ()
			four ()
		three ()
	two ()
one ()



RE: function defined inside a function - Skaperen - May-13-2021

i could imagine something counting the steps to search for a variable name and something counting the steps a checking for a number like 65535 or a rollover to 0 with a comment // SanityError exception.