How To/python/

#!python
 
"""
execfile(str filename)
 
[pl]
funkcja wczytuje i wykonuje plik podany jako parametr jakby był kodem
python. Różnica między funkcją execfile() a importem plików polega na tym,
że plik załączany przez execfile() ma dotęp do tej samej przestrzeni
nazw co plik do którego jest wczytywany, podczas gdy plik importowany
dyrektywą import tworzy własną przestrzeń nazw. 
 
execfile() działa podobnie jak include() lub require() w PHP.
 
[en]
function reads and executes file given as a parameter treating it as 
python code. Difference between execfile() and import statement is that 
file included with execfile() has access to the same namespace as file 
it is included by. When import statement is used imported file creates 
its own namespace.
 
execfile() is similar to PHP's include() or require() functions.
"""
 
"""
execfile() example
"""
 
#file1.py
myVar = 'I AM VISIBLE!'
execfile('file2.py')
myPrint()
 
#file2.py
def myPrint():
    print 'CODE LOADED!'
    print myVar
 
[...]$ python file1.py
CODE LOADED!
I AM VISIBLE!
 
 
"""
import example
"""
 
#file1.py
import file2
myVar = 'I AM VISIBLE!'
file2.myPrint()
 
#file2.py
def myPrint():
    print myVar
 
[...]$ python file1.py
CODE LOADED!
Traceback (most recent call last):
  File "file1.py", line 3, in <module>
    file2.myPrint()
  File "\home\dummy\python\file2.py", line 3, in myPrint
    print myVar
NameError: global name 'myVar' is not defined