Modules
1300 ワード
module_using_sys.py
module.using_name.py
mymodule.py
mymodule_demo.py
mymodule_demo2.py
#
# Modules
# .py
# Python
# C Python
#
import sys
print('The command line arguments are:')
for item in sys.argv:
print(item)
print('The PYTHONPATH is', sys.path,'
')
module.using_name.py
#
# Python , .pyc
#
# improt from...import
from math import sqrt
print('Square root of 16 is', sqrt(16))
#
# __name__
if __name__ == '__main__':
print('This program is being run by itself')
else:
print('I am being imported from another module')
mymodule.py
def say_hi():
print('Hi, this is mymodule speaking.')
__version__ = '0.1'
mymodule_demo.py
# module mymodule environment path
import mymodule
mymodule.say_hi()
print('Version', mymodule.__version__)
mymodule_demo2.py
from mymodule import say_hi,__version__
say_hi()
print('Version', __version__)
# from mymodule import *
# say_hi , __version__