arganzheng 发表于 2013-2-1 12:33:38

python学习笔记之module && package

<div style="">

<div style=""><span style="font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif;"><div style=""><div style="line-height: 1.5;"><div style="line-height: 18px; margin-top: 10px; clear: both; font-family: Helvetica, Arial, sans-serif; font-size: 15px;" class="pageSection"><div style="line-height: 1.5;"><div style="line-height: 1.5; margin-bottom: 5px; padding-top: 2px; padding-right: 0px; padding-bottom: 2px; padding-left: 0px;" class="section-header"><div style=""><div style="line-height: 1.5;" class="wiki-content">python学习笔记之module && package

python的module

<ol style=""><li style="line-height: 1.5; font-size: 14px; font-family: Helvetica, Arial, sans-serif; padding: 0px; margin: 0px;">import只能导入模块,不能导入模块中的对象(类、函数、变量等)。如一个模块A(A.py)中有个函数getName,另一个模块不能通过import A.getName将getName导入到本模块,只能用import A。如果想只导入特定的类、函数、变量则用from A import getName即可。<li style="line-height: 1.5; font-size: 14px; font-family: Helvetica, Arial, sans-serif; padding: 0px; margin: 0px;">import一个module时,会执行该module的所有方法,并且将该module添加到importing module的命名空间中。A module's body executes immediately the first time the module is imported in a given run of a program...An import statement creates a new namespace containing all the attributes of the module. 如:<li style="line-height: 1.5; padding: 0px; margin: 0px;"><div style="line-height: 1.5; color: black; margin-top: 10px; margin-right: 20px; margin-bottom: 10px; margin-left: 20px; background-color: #ffffff; font-size: 14px; font-family: Helvetica, Arial, sans-serif; padding: 0px; border: 1px solid #3c78b5;" class="code panel"><div style="line-height: 2; padding-top: 0px; padding-right: 12px; padding-bottom: 0px; padding-left: 12px; text-align: center; border-bottom-width: 1px; border-bottom-style: solid; background-color: #f0f0f0; border-bottom-color: #3c78b5;" class="codeHeader panelHeader">fibo.py
页: [1]
查看完整版本: python学习笔记之module && package