In the following example:
def speak(volume):
def whisper(text):
print(text.lower() + ('.' * volume))
def yell(text):
print (text.upper() + ('!' * volume))
if volume > 1:
return yell
elif volume <= 1:
return whisper
func = speak(volume=10)
func('hello')
HELLO!!!!!!!!!! # <== obviously `10` is stored in `func` somewhere
Given func
, how would I get the "volume"? Is there something within the func
namespace which gives the value of 10
? I thought perhaps it would be in func.__globals__
or func.__dict__
but it's in neither.