The most comment package managers are pip and easy_install(replaced by its successor pip).
By default, python module installed by pip is located in a site-packages folder(added to sys.path by default). Every time python wants to find a module, it looks in to sys.path.
Here is a snippet on adding module to sys.path:
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), 'site-packages'))
# duplicated modules existed, use the following line instead to insert into the front of `sys.path`
# sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'site-packages'))import sys
import inspect
# list all the fields and methods of `sys` object as a tuple
dir(sys)
# list all the fields and methods with their doc
inspect.getmembers(sys)
# list builtin function of `sys`
inspect.getmembers(sys.modules['os'], predicate=inspect.isbuiltin)
# try __dict__ property
sys.__dict__
# getting help
help(sys)
# using built-in functions
[method for method in dir(sys) if callable(getattr(sys, method))]dir() and inspect.getmembers() include base class methods, while __dict__ does not.
- built-in function, built-in operator, lambda syntax finding-what-methods-an-object-has on stackoverflow
- built-in function how-do-i-look-inside-a-python-object on stackoverflow
- sys.modules, globals(), pyclbr how-can-i-get-a-list-of-all-classes-within-current-module-in-python on stackoverflow
- closure, doc, name, decorators python-introspection-access-function-name-and-docstring-inside-function-definit on stackoverflow
- detail about dir(), how-to-get-a-complete-list-of-objects-methods-and-attributes on stackoverflow
- python-decorators-in-12-step
# use `iteritems()` to avoid `too many value to unpack` ValueError because python can only unpack 5 values at most
[module for module, doc in sys.modules.iteritems()]wsgi(Python Web Server Gateway Interface) is a Python standard described by PEP(Python Enhancement Proposals). It's a python solution for ruby's rack.
add the following line to the header of python source file in order to run it on the terminal even without .py extension.
#!/usr/bin/pythonor
#!/usr/bin/env pythonthis is considered better than the previous, because it uses python in the ENVIRONMENT variable.