Created
December 14, 2011 05:34
-
-
Save dketov/1475410 to your computer and use it in GitHub Desktop.
Пространства имён
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Использование атрибутов, методов и классов модуля | |
""" | |
import library | |
library.sys | |
print library.name | |
print library.func, library.klass | |
print library.__dict__.keys() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Изменение атрибутов модуля | |
""" | |
import simple # first import: loads and runs file's code | |
print simple.spam # assignment makes an attribute | |
simple.spam = 2 # change attribute in module | |
import simple # just fetches already-loaded module | |
print simple.spam # code wasn't rerun: attribute unchanged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Атрибуты модуля и глобальные переменные | |
""" | |
X = 11 # my X: global to this file only | |
import globs # gain access to names in moda | |
globs.f() # sets globs.X, not my X | |
print X, globs.X |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Перезагрузка модуля | |
""" | |
import changer | |
changer.printer() | |
import changer | |
changer.printer() # no effect: uses loaded module | |
reload(changer) # forces new code to load/run | |
changer.printer() # runs the new version now |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Модуль changer | |
""" | |
#File: changer.py | |
message = "First version" | |
def printer(): | |
print message |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Модуль globs | |
""" | |
#File: globs.py | |
X = 88 # my X: global to this file only | |
def f(): | |
global X # change my X | |
X = 99 # cannot see names in other modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Модуль library | |
""" | |
#File: library.py | |
print 'starting to load...' | |
import sys | |
name = 42 | |
def func(): pass | |
class klass: pass | |
print 'done loading.' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
""" | |
Модуль simple | |
""" | |
#File: simple.py | |
print 'hello' | |
spam = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment