Jesse's Blog » 日志 » Notes_6_on <Learning Python>
Notes_6_on <Learning Python>
Jesse 发表于 2008-06-05 21:15:18
Part.V Modules
1. P260
from assigns one or more names to objects of the same name in another module.
There is no link from a name copied with from back to the file it came from.
Like passing function arguments.
2. P264
The global scope for mod.foo is always the file enclosing it, regardless of which module it is ultimately called from:
**Functions can never see names in other functions, unless they are *physically* enclosing.
**Module code can never see names in other modules unless they are *explicitly* imported.
*lexical scope*: the scopes surrounding a piece of code are *completely* determined from the code's *physical* position in the file.
3. P287
def foo():
print bar()
def bar():
return 'hello'
This piece of code works because:
code at the top level of a module file (not nested in a function) runs as soon as Python reaches it during an import;
code inside a function body doesn't run until the funtion is called
i.e. forward references are only a concern in top-level module code that executes immediately; functions can reference names arbitrarily.
1. P260
from assigns one or more names to objects of the same name in another module.
There is no link from a name copied with from back to the file it came from.
Like passing function arguments.
2. P264
The global scope for mod.foo is always the file enclosing it, regardless of which module it is ultimately called from:
**Functions can never see names in other functions, unless they are *physically* enclosing.
**Module code can never see names in other modules unless they are *explicitly* imported.
*lexical scope*: the scopes surrounding a piece of code are *completely* determined from the code's *physical* position in the file.
3. P287
def foo():
print bar()
def bar():
return 'hello'
This piece of code works because:
code at the top level of a module file (not nested in a function) runs as soon as Python reaches it during an import;
code inside a function body doesn't run until the funtion is called
i.e. forward references are only a concern in top-level module code that executes immediately; functions can reference names arbitrarily.
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
