Python에 있어 module은 하나의 python 코드 파일을 의미한다. 파일 이름 자체가 module을 나타내는 이름이다. 반면 package는 module을 모아 놓은 directory 구조하고 할 수 있다.
module 과 package 사용의 예>
import ModuleName
import PackageName
from PackageName import ModuleName
import를 하게 되면 해당 ModuleName 혹은 PackageName 이 Loading 상태인지 확인 후 Loading이 되지 않은 상태라면 다음의 위치에서 존재를 확인한다.
1) sys.path 에 선언된 위치
2) 현재 실행 위치
Ubuntu 14.04 python 2.7에서 sys.path를 확인해 보면 다음과 같다.
>>> print sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
그리고 위의 경로에서 사용가능한 module/package의 종류는 다음과 같이 확인이 가능하다.
(예를 들어 email 같은 경우는 package인데 아래 목록에 표시된 것을 확인할 수 있다.)
>>> help('modules')
Please wait a moment while I gather a list of all available modules...
ANSI apt_inst hashlib reportlab
BaseHTTPServer apt_pkg heapq repr
Bastion aptdaemon hmac reprlib
CDROM aptsources hotshot resource
CGIHTTPServer argh hpmudext rexec
Canvas argparse html rfc822
CommandNotFound array html5lib rlcompleter
ConfigParser asn1crypto htmlentitydefs robotparser
Cookie ast htmllib rsa
Crypto asynchat http runpy
DLFCN asyncore httplib samba
Dialog atexit httplib2 scanext
DocXMLRPCServer atk ibus sched
FSM audiodev idna scipy
FileDialog audioop ihooks screen
FixTk axi imaplib select
HTMLParser backports imghdr selenium
IN base64 imp serial
Image bcrypt importlib sessioninstaller
ImageChops bdb imputil sets
ImageColor binascii indicator_keyboard setuptools
ImageCrackCode binhex inspect sgmllib
ImageDraw bisect io sha
ImageEnhance bonobo ipaddress shelve
ImageFile bs4 itertools shlex
ImageFileIO bsddb json shutil
ImageFilter builtins keybinder signal
ImageFont bz2 keyword sip
ImageGL cPickle kiwisolver sipconfig
ImageGrab cProfile ldb sipconfig_nd
ImageMath cStringIO lib2to3 site
ImageOps cachetools libfuturize sitecustomize
ImagePalette cairo libpasteurize six
ImagePath calendar libuser smbc
ImageQt cffi libxml2 smtpd
ImageSequence cgi libxml2mod smtplib
ImageStat cgitb linecache sndhdr
ImageTk chardet linuxaudiodev socket
ImageWin chunk locale socketserver
MimeWriter click lockfile softwarecenter_aptd_plugins
ORBit cmath logging spwd
OpenSSL cmd lsb_release sqlite3
PAM code lxml sre
PIL codecs macpath sre_compile
PSDraw codeop macurl2path sre_constants
PngImagePlugin collections mailbox sre_parse
PyQt4 colorama mailcap ssl
Queue colorsys markupbase stat
ScrolledText commands marshal statvfs
SimpleDialog compileall math string
SimpleHTTPServer compiler matplotlib stringold
SimpleXMLRPCServer concurrent md5 stringprep
SocketServer contextlib mechanize strop
StringIO cookielib mhlib struct
TYPES copy mimetools subprocess
Tix copy_reg mimetypes subprocess32
Tkconstants copyreg mimify sunau
Tkdnd crypt mmap sunaudio
Tkinter cryptography modulefinder symbol
UbuntuSystemService csv multifile symtable
UserDict ctypes multiprocessing sys
UserList cups mutex sysconfig
UserString cupsext nacl syslog
_LWPCookieJar curses netrc tabnanny
_MozillaCookieJar cycler networkx talloc
__builtin__ datetime new tarfile
__future__ dateutil nis tdb
_abcoll dbhash nntplib telnetlib
_ast dbm ntpath tempfile
_bisect dbus nturl2path termios
_bsddb deb822 numbers test
_cffi_backend debconf numpy textwrap
_codecs debian oauthlib this
_codecs_cn debian_bundle oneconf thread
_codecs_hk debtagshw opcode threading
_codecs_iso2022 decimal operator time
_codecs_jp defer optparse timeit
_codecs_kr difflib os tkColorChooser
_codecs_tw dircache os2emxpath tkCommonDialog
_collections dirspec ossaudiodev tkFileDialog
_csv dis pango tkFont
_ctypes distlib pangocairo tkMessageBox
_ctypes_test distutils paramiko tkSimpleDialog
_curses dns parse tkinter
_curses_panel doctest parser toaiff
_dbus_bindings drv_libxml2 past token
_dbus_glib_bindings dsextras pathtools tokenize
_dummy_thread dumbdbm pcardext trace
_elementtree dummy_thread pdb traceback
_functools dummy_threading pexpect ttk
_hashlib duplicity pickle tty
_heapq easy_install pickletools turtle
_hotshot easyprocess pip twisted
_io email pipes types
_json encodings piston_mini_client ubuntu_sso
_ldb_text ensurepip pkg_resources unicodedata
_locale enum pkgutil unittest
_lsprof errno platform uritemplate
_markerlib exceptions plistlib urllib
_markupbase fcntl ply urllib2
_md5 fdpexpect popen2 urllib3
_multibytecodec filecmp poplib urlparse
_multiprocessing fileinput posix user
_osx_support fnmatch posixfile uu
_posixsubprocess formatter posixpath uuid
_pyio fpformat pprint virtualenv
_random fractions profile vte
_sha ftplib pstats warnings
_sha256 functools pty watchdog
_sha512 future pwd wave
_smbc future_builtins pxssh weakref
_socket gc py_compile webbrowser
_sqlite3 gconf pyasn1 webencodings
_sre gdbm pyasn1_modules wheel
_ssl genericpath pyclbr whichdb
_strptime getopt pycparser winreg
_struct getpass pydoc wsgiref
_symtable gettext pydoc_data xapian
_sysconfigdata gi pyexpat xdg
_sysconfigdata_nd gio pygtk xdiagnose
_tdb_text glib pygtkcompat xdrlib
_testcapi glob pyinotify xml
_thread gnome pylab xmllib
_threading_local gnomecanvas pymysql xmlrpc
_tkinter gnomekeyring pynotify xmlrpclib
_warnings gnomevfs pyparsing xxsubtype
_weakref gobject pytz yaml
_weakrefset google pyvirtualdisplay zeitgeist
abc grp queue zipfile
aifc gtk quopri zipimport
antigravity gtkunixprint random zlib
anydbm gyp re zope
apt gzip readline
Enter any module name to get more help. Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".
'Language > Python' 카테고리의 다른 글
Python - random(), 임의의 수(난수)를 구하는 함수 (0) | 2019.03.20 |
---|---|
Python - Python 2 에서 Python 3 으로의 전환 (0) | 2019.03.19 |
Python - id(), object의 unique 값(memory address)를 보여주는 함수 (0) | 2019.03.18 |
Python - if __name__ == __main__ 의 의미 (0) | 2019.02.08 |
Python - datetime/time module, 현재 시간 출력 방법 (0) | 2018.06.16 |
Python - email package, raw email message 다루기 (0) | 2018.06.15 |
Python - poplib, POP3 를 통한 이메일 수신 (0) | 2018.06.15 |
Python - divmod(), 두 숫자를 나누어 몫과 나머지를 tuple로 반환하는 함수 (0) | 2018.01.13 |