error"func not yet assigned def func ()print(func ()ok"func looked up later func (error"func not yet assigned def func ()return "hellofunc (ok"func and "func assigned when this file is imported (or run as standalone program)python executes its statements from top to bottom the first call to func fails because the func def hasn' run yet the call to func inside func works as long as func ' def has been reached by the time func is called--and it hasn' when the second top-level func call is run the last call to func at the bottom of the file works because func and func have both been assigned mixing defs with top-level code is not only difficult to readit' also dependent on statement ordering as rule of thumbif you need to mix immediate code with defsput your defs at the top of the file and your top-level code at the bottom that wayyour functions are guaranteed to be defined and assigned by the time python runs the code that uses them from copies names but doesn' link although it' commonly usedthe from statement is the source of variety of potential gotchas in python as we've learnedthe from statement is really an assignment to names in the importer' scope-- name-copy operationnot name aliasing the implications of this are the same as for all assignments in pythonbut they're subtleespecially given that the code that shares the objects lives in different files for instancesuppose we define the following modulenested pynested py def printer()print(xif we import its two names using from in another modulenested pywe get copies of those namesnot links to them changing name in the importer resets only the binding of the local version of that namenot the name in nested pynested py from nested import xprinter printer(python nested py advanced module topics copy names out changes my "xonlynested ' is still