码迷,mamicode.com
首页 > 编程语言 > 详细

Python module

时间:2014-12-26 16:53:37      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:python module   note to self   

1. module name

    fibo.__name__

    # file fibo.py

   def f(x):

         return x*x

   import fibo

   fibo.f(10) # module name then function name

   fl = fibo.f # to make it call like locally

   from fibo import f

   from fibo import * # import all except  for name start with ‘_‘

2. module search path

    a. current path

    b. pythonpath

    c. path

    #  not find or not set pythonpath search installment path(/usr/local/lib/python)

3. while pyc time not the same as py time, drop it(byte compiled)

    pyc is standalone for plant

    -O pyo, optimize the code(delete allert)

    -OO pyo, delete __doc__ string

    pyc or pyo file doesn‘t mean run faster than py, but load faster

    it will not create a pyc or pyo when run command line

    compileall can create .pyc for all module in some path

4. import sys

    sys.ps1( >>>) sys.ps2(...) those two variable only defined if the interpreter is interactive mode

5. change sys path

    import sys

    sys.path.append(/usr/guido/lib/python)

6. dir()

    import flib,sys

    dir(flib)

    dir() # show current definition include function, variable, module

    it will not show inner function and variable and can reset it from __builtin__

7. package

    Sound/

         __init__.py

        Formats/

                 __init__.py

                wavread.py

                wavwrite.py

                ...

        Effects/

               __init__.py

               echo.py

               ...

        Filter/

              equalizer.py

     it is necessary exit a __init__.py file

     import Sound.Effects.echo

     Sound.Effects.echo.echofilter(input,output,delay=0.7,atten=4)

    

     from Sound.Effects import echo

     echo.echofilter(input,output,delay=0.7,atten=4)

    

     from Sound.Effects.echo import echofilter

     echofilter(input,output,delay=0.7,atten=4)

     from package import item (item can be subpackage,module,function,class,variable),if can‘t find this item then importError exception

     import package.subpackage.item(item must be subpackage or module in this situation)

    

     from Package import specific_subpackage

     __init__.py have a statement __all__ = [‘reverse‘,‘echo‘,‘surround‘]

 8.especially variable ( __path__ )  before __init__.py  execute this variable get a initial list, use to extend a package‘s module set.

Python module

标签:python module   note to self   

原文地址:http://blog.csdn.net/zcliatb/article/details/42171179

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!