Skip to content

Instantly share code, notes, and snippets.

@dketov
Created December 14, 2011 05:29
Show Gist options
  • Save dketov/1475397 to your computer and use it in GitHub Desktop.
Save dketov/1475397 to your computer and use it in GitHub Desktop.
Использование модулей
# -*- encoding: utf-8 -*-
"""
Импортирование модуля
"""
import printer # get module as a whole
printer.printer('Hello world!') # qualify to get names
# -*- encoding: utf-8 -*-
"""
Включение имени из модуля в область видимости
"""
from printer import printer # copy out one variable
printer('Hello world!') # no need to qualify name
# -*- encoding: utf-8 -*-
"""
Включение всех имен из модуля в область видимости
"""
from printer import * # copy out all variables
printer('Hello world!')
# -*- encoding: utf-8 -*-
"""
Словарь загруженных модулей
"""
import sys
print '\n'.join(sys.modules.keys())
# -*- encoding: utf-8 -*-
"""
Простейший модуль
"""
#//File: printer.py
def printer(x): # module attribute
print x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment