Python only ever has a local and global namespace. In your example B was never defined in the namespace of A. Here’s your code using local namespaces.
def A():
def B():
return "blagh"
print B()
return
A()
You’re likely using this in a component action script. I’m not sure that you can easily reference that namespace, even from what would seem to be a “sibling” namespace (remember only 2, not a hierarchy).
Use Script Modules (Project->Script Modules or cntl+M) to make functions globally accessible. For example, create a module called test under the app package with the following code:
def A():
import app.test
print app.test.B()
return
def B():
return "Blah"
On the component action, use either:
app.test.A()
print app.test.B()
Keep in mind that the app and fpmi packages have been pre-imported for you on component Actions. You need to import packages in order to call their functions within the Script Modules section.
Nathan’s post is right on. I just wanted to add that because functions are objects in Python, they can be passed around. So you could have modified your code to this and had it work: