Python module

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值