1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
----------------
"""This is a python file to demonstrate how to use Module and Package in python"""
__all__ = ["greeting","string"]
__author__ = "xxx@email"
import sys
string = "I'm a test program"
def _private_hello(): return 'Hello, World!'
def __private_hi(name): return 'Hi, %s' % name
def greeting(): args = sys.argv if len(args) == 1: return _private_hello() elif len(args) == 2: return __private_hi(args[1]) else: print('Too many arguments!')
if __name__ == '__main__': result = greeting() print(result)
(venv3.7) ➜ testpackage python testmodule.py Hello, World! (venv3.7) ➜ testpackage python testmodule.py Aaron Hi, Aaron
>>> import testmodule >>> testmodule.greeting() 'Hello, World!' >>> testmodule.string "I'm a test program" >>> testmodule.__all__ ['greeting', 'string'] >>> testmodule.__doc__ 'This is a python file to demonstrate how to use Module and Package in python' >>> testmodule._private_hello() 'Hello, World!'
|