Python Forum

Full Version: function defined inside a function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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 ()
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.