python tutorial 學習筆記(三)

module –> .py file

  •  
    • import  module_name
    • from module_name import *
    • module_name.__name__ #returns the module name

module can contain executable statments. They are executed only the first time the module is imported somewhere.

__name__ is “__main__” when the file is executed as main file. Thus statments after “if __name__ == “__main__:” are executed only when the file is main file.

Standard Modules

Python Libraray Reference.

sys module: sys.ps1, sys.path

__builtin__ module: just a name, already built-in

built-in function dir(): which names a module defines

Module Search Path

current directory( the main file directory)

PYTHONPATH(sys.path)

installation-dpendent default

Package:

must contain __init__.py file, it can define a list named __all__, containing all module names that should be imported when use “from package import *”

import p1.p2.module

from package import item, item can be a submodule or a function, calss or variable defined in the package

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章