In [ ]:
# why do we save our programs as .py
# platform independent.
# convience - just to look and say that its a python program.
# saving a program in .py makes it a modules.( A python program which can be used later)

In [ ]:
# program1.py -> f1,f2,f3,f4,f5
# program2.py -> f1,f2,f3,program1.f1
# re-usability of the code.
# we need not worry about the namespaces around the programs.

In [1]:
help()


Welcome to Python 2.7!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/2.7/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> modules
WARNING:OpenGL.Tk:Expected Tk Togl installation in /usr/lib/python2.7/dist-packages/OpenGL/Tk/togl-linux2-64
Please wait a moment while I gather a list of all available modules...

ANSI
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:127: RuntimeWarning: PyOS_InputHook is not available for interactive use of PyGTK
  set_interactive(1)
                _multibytecodec     future_builtins     random
BaseHTTPServer      _multiprocessing    gc                  re
Bastion             _osx_support        gconf               readline
CDROM               _pyio               genericpath         repr
CGIHTTPServer       _random             getopt              requests
Canvas              _sha                getpass             resource
ConfigParser        _sha256             gettext             rexec
Cookie              _sha512             gi                  rfc822
Crypto              _socket             gio                 rlcompleter
DLFCN               _sqlite3            glib                rmagic
Dialog              _sre                glob                robotparser
DocXMLRPCServer     _ssl                gobject             roman
FSM                 _strptime           grp                 runpy
FileDialog          _struct             gtk                 samba
FixTk               _symtable           gtkspell            sched
HTMLParser          _sysconfigdata      gtkunixprint        screen
IN                  _sysconfigdata_nd   gzip                select
IPython             _testcapi           hashlib             serial
Image               _threading_local    heapq               service_identity
ImageChops          _tkinter            hmac                sets
ImageColor          _warnings           hotshot             setuptools
ImageCrackCode      _weakref            html5lib            sgmllib
ImageDraw           _weakrefset         htmlentitydefs      sha
ImageEnhance        abc                 htmllib             shelve
ImageFile           aifc                httplib             shlex
ImageFileIO         antigravity         httplib2            shutil
ImageFilter         anydbm              idlelib             signal
ImageFont           appindicator        idna                simplegeneric
ImageGL             apt                 ihooks              sip
ImageGrab           apt_inst            imaplib             sipconfig
ImageMath           apt_pkg             imghdr              sipconfig_nd
ImageOps            aptdaemon           imp                 site
ImagePalette        aptsources          importlib           sitecustomize
ImagePath           argparse            imputil             six
ImageQt             array               indicator_keyboard  smtpd
ImageSequence       ast                 inspect             smtplib
ImageStat           asynchat            io                  sndhdr
ImageTk             asyncore            ipaddress           socket
ImageWin            atexit              itertools           softwarecenter_aptd_plugins
MimeWriter          atk                 jinja2              sphinx
OpenGL              audiodev            json                spwd
OpenSSL             audioop             jwt                 sqlite3
PAM                 autoreload          keyword             sre
PIL                 axi                 ldb                 sre_compile
PSDraw              base64              lib2to3             sre_constants
PngImagePlugin      bdb                 libvboxjxpcom       sre_parse
PyQt4               binascii            linecache           ssl
PySide              binhex              linuxaudiodev       stat
Pyrex               bisect              locale              statvfs
Queue               blinker             lockfile            storemagic
ScrolledText        bs4                 logging             string
SimpleDialog        bsddb               lsb_release         stringold
SimpleHTTPServer    bz2                 lxml                stringprep
SimpleXMLRPCServer  cPickle             macpath             strop
SocketServer        cProfile            macurl2path         struct
StringIO            cStringIO           mailbox             subprocess
TYPES               cairo               mailcap             sunau
Tix                 calendar            markupbase          sunaudio
Tkconstants         cffi                markupsafe          symbol
Tkdnd               cgi                 marshal             sympyprinting
Tkinter             cgitb               math                symtable
UbuntuSystemService characteristic      md5                 sys
UserDict            chardet             mhlib               sysconfig
UserList            chunk               mimetools           syslog
UserString          cmath               mimetypes           tabnanny
VBoxAuth            cmd                 mimify              talloc
VBoxAuthSimple      code                mmap                tarfile
VBoxDD              codecs              modulefinder        tdb
VBoxDD2             codeop              multifile           telnetlib
VBoxDDU             collections         multiprocessing     tempfile
VBoxDbg             colorama            mutex               termios
VBoxDragAndDropSvc  colorsys            ndg                 test
VBoxGuestControlSvc commands            ndiff               test_characteristic
VBoxGuestPropSvc    compileall          netrc               textwrap
VBoxHeadless        compiler            new                 this
VBoxHostChannel     contextlib          nis                 thread
VBoxKeyboard        cookielib           nntplib             threading
VBoxNetDHCP         copy                ntdb                time
VBoxNetNAT          copy_reg            ntpath              timeit
VBoxOGLhostcrutil   crypt               nturl2path          tkColorChooser
VBoxOGLhosterrorspu cryptography        numbers             tkCommonDialog
VBoxOGLrenderspu    csv                 oauthlib            tkFileDialog
VBoxPython          ctypes              octavemagic         tkFont
VBoxPython2_7       cups                oneconf             tkMessageBox
VBoxREM             curl                opcode              tkSimpleDialog
VBoxRT              curses              operator            toaiff
VBoxSDL             cythonmagic         optparse            token
VBoxSharedClipboard datetime            os                  tokenize
VBoxSharedCrOpenGL  dbhash              os2emxpath          tornado
VBoxSharedFolders   dbm                 ossaudiodev         trace
VBoxVMM             dbus                pango               traceback
VBoxVMMPreload      deb822              pangocairo          ttk
VBoxXPCOM           debconf             parallelmagic       tty
VBoxXPCOMC          debian              parser              turtle
VirtualBox          debian_bundle       pdb                 twisted
Xlib                debtagshw           pexpect             types
_LWPCookieJar       decimal             pickle              ubuntu_sso
_MozillaCookieJar   decorator           pickletools         unicodedata
__builtin__         defer               pip                 unittest
__future__          difflib             pipes               urllib
_abcoll             dircache            piston_mini_client  urllib2
_ast                dirspec             pkg_resources       urllib3
_bisect             dis                 pkgutil             urlparse
_bsddb              distlib             platform            user
_cffi_backend       distutils           plistlib            uu
_codecs             doctest             ply                 uuid
_codecs_cn          docutils            popen2              vboxapi
_codecs_hk          dsextras            poplib              vboxshell
_codecs_iso2022     dumbdbm             posix               virtualenv
_codecs_jp          dummy_thread        posixfile           virtualenv_support
_codecs_kr          dummy_threading     posixpath           warnings
_codecs_tw          duplicity           pprint              wave
_collections        easy_install        profile             weakref
_csv                email               pstats              webbrowser
_ctypes             encodings           pty                 wheel
_ctypes_test        ensurepip           pwd                 whichdb
_curses             enum                pxssh               wsgiref
_curses_panel       errno               py_compile          xapian
_dbus_bindings      exceptions          pyasn1              xdg
_dbus_glib_bindings fcntl               pyasn1_modules      xdiagnose
_elementtree        fdpexpect           pyclbr              xdrlib
_functools          filecmp             pycparser           xml
_hashlib            fileinput           pycurl              xmllib
_heapq              fluxgui             pydoc               xmlrpclib
_hotshot            fnmatch             pydoc_data          xxsubtype
_io                 formatter           pyexpat             zim
_json               fpectl              pygments            zipfile
_locale             fpformat            pygtk               zipimport
_lsprof             fractions           pygtkcompat         zlib
_markerlib          ftplib              pymysql             zmq
_md5                functools           quopri              zope

Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".

help> quit()
no Python documentation found for 'quit()'

help> quit

You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.

In [ ]:
# https://pypi.python.org/pypi
# complete repository of modules.

In [ ]:
# how to use modules.
# importing the module using the name.

In [1]:
import math

In [3]:
import math1


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-628bade712e2> in <module>()
----> 1 import math1

ImportError: No module named math1

In [4]:
print dir(math)


['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']

In [5]:
print math.pi


3.14159265359

In [7]:
print help(math.pow)


Help on built-in function pow in module math:

pow(...)
    pow(x, y)
    
    Return x**y (x to the power of y).

None

In [8]:
print math.pow(2,3)


8.0

In [ ]:
# importing modules using aliases.

In [9]:
import math as m

In [10]:
print m.pow(2,3)


8.0

In [11]:
print m.pi


3.14159265359

In [ ]:
# Making the modules part of our local namespaces

In [4]:
from math import pi,pow

In [6]:
print pi


3.14159265359

In [7]:
# when using the above method make it a point to not have values with the similar name.
pi=10
print pi


10

In [14]:
print pow(2,3)


8.0

In [ ]:
# DONT TRY THIS AT HOME OR OFFICE
# from math import *
# NOT RECOMMENED.