COPY & SYS

Python copy及SYS模块详解
本文介绍了Python中copy模块的浅拷贝与深拷贝的区别,并通过实例展示其工作原理。此外,还详细解释了sys模块的主要功能,包括从外部传递参数、获取模块搜索路径、记录已导入模块等。

一、copy

import copy  
# copy 和 deepcopy 对比
a = [1, 2, 3, 4, ['a', 'b']] #原始对象  
  
b = a #赋值,传对象的引用  
c = copy.copy(a) #对象拷贝,浅拷贝  
d = copy.deepcopy(a) #对象拷贝,深拷贝  
  
a.append(5) #修改对象a  
a[4].append('c') #修改对象a中的['a', 'b']数组对象  
  
print 'a = ', a  
print 'b = ', b  
print 'c = ', c  
print 'd = ', d  


输出结果: 
a = [1, 2, 3, 4, ['a', 'b', 'c'], 5] 
b = [1, 2, 3, 4, ['a', 'b', 'c'], 5] 
c = [1, 2, 3, 4, ['a', 'b', 'c']] 
d = [1, 2, 3, 4, ['a', 'b']]

二、SYS

1、argv:实现从程序外部向程序传递参数。

2、path:获取指定模块搜索路径的字符串集合,可以将写好的模块放在得到的某个路径下,就可以在程序中import时正确找到。

3、modules:sys.modules是一个全局字典,该字典是python启动后就加载在内存中。每当程序员导入新的模块,sys.modules将自动记录该模块。当第二次再导入该模块时,python会直接到字典中查找,从而加快了程序运行的速度。它拥有字典所拥有的一切方法。

4、stdin , stdout , 以及stderr 变量包含与标准I/O 流对应的流对象. 如果需要更好地控制输出,而print 不能满足你的要求, 它们就是你所需要的. 你也可以替换它们, 这时候你就可以重定向输出和输入到其它设备( device ), 或者以非标准的方式处理它们

5、platform:获取当前系统平台。

6、exit(status=None):程序中间的退出。

7、getrefcount():返回对象的调用次数。

8、getdefaultencoding():获取系统当前编码,一般默认为ascii。

9、getfilesystemencoding():获取文件系统使用编码方式,Windows下返回'mbcs',mac下返回'utf-8'.

根据下面的页面代码,需要编写这个js点击事件,点击明细表中每行的name为extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e5946689e29d2)的输入框,能跳转到对应这个输入框的value里面的链接地址,页面代码如下:<tr> <td row="2" column="0,1,2,3" class="td_normal_title" colspan="4" style="width: auto;" width="undefined"> <script> $(function() { var tb = document.getElementById('TABLE_DL_fd_3e59465a09231a'); tb.setAttribute('tbdraggable', 'true'); }); </script> <script> Com_IncludeFile('doclist.js'); </script> <script id="doclist_js" src="/resource/js/doclist.js?s_cache=1754870647847"></script> <script id="doclistdnd_js" src="/resource/js/doclistdnd.js?s_cache=1754870647847"></script> <script> DocList_Info.push('TABLE_DL_fd_3e59465a09231a'); </script> <script> Com_IncludeFile('detailsTableFreeze.css', Com_Parameter.ContextPath + 'sys/xform/designer/resource/css/', 'css', true); </script> <link rel="stylesheet" href="/sys/xform/designer/resource/css/detailsTableFreeze.css?s_cache=1754870647847"> <script> Com_IncludeFile('detailsTableFreeze.js', Com_Parameter.ContextPath + 'sys/xform/designer/resource/js/', 'js', true); </script> <script id="detailsTableFreeze_js" src="/sys/xform/designer/resource/js/detailsTableFreeze.js?s_cache=1754870647847"></script> <script> Com_AddEventListener(window, 'load', function() { setTimeout(function() { for (var i = 0; i < 1; i++) { DocList_AddRow(document.getElementById('TABLE_DL_fd_3e59465a09231a')) }; tableFreezeStarter('TABLE_DL_fd_3e59465a09231a', false, undefined, false, true, 'add'); }, 500); }); </script> <table label="明细表1" id="TABLE_DL_fd_3e59465a09231a" align="center" class="tb_normal" tablename="fd_3e5946528a2834" style="width: 100%;" data-multihead="false" width="100%" showindex="true" showrow="1" showstatisticrow="undefined" showcopyopt="undefined" dataentrymode="multipleRow" required="undefined" performance="undefined" excelexport="undefined" excelimport="undefined" defaultfreezetitle="undefined" defaultfreezecol="undefined" layout2col="undefined" fd_type="detailsTable" tbdraggable="true"> <tbody> <tr class="tr_normal_title" type="titleRow" style="height: 33px;" invalidrow="true"> <td row="1" column="0" align="center" coltype="selectCol" style="width: 15px;"></td> <td row="0" column="1" align="center" class="td_normal_title" coltype="noTitle" style="width: 25px; white-space: nowrap;">序号</td> <td row="0" column="2" align="center" class="td_normal_title"> <label class="xform_label" line="normal" fd_type="textLabel" style="display: inline-block; width: auto; word-break: break-all; overflow-wrap: break-word;;word-break:break-all;;word-wrap:break-word;">文本1</label> </td> <td row="0" column="3" align="center" class="td_normal_title"> <label class="xform_label" line="normal" style="display: inline-block; width: auto; word-break: break-all; overflow-wrap: break-word;;word-break:break-all;;word-wrap:break-word;" fd_type="textLabel">文本3</label> </td> <td row="0" column="4" align="center" class="td_normal_title"></td> <td row="0" column="5" align="center" class="td_normal_title" coltype="blankTitleCol" style="width:48px;"></td> </tr> <tr class="" trdraggable="true" style="cursor: move; user-select: none;"> <td class="" align="center" valign=""><input type="checkbox" name="DocList_Selected" onclick="DocList_SelectRow(this);"></td> <td class="" align="center" valign="">1</td> <td class="" align="center" valign=""> <div class="xform_inputText" canshow="true" fd_type="inputText" style="display: inline-block; width: 147px; word-break: break-all; overflow-wrap: break-word;"> <xformflag flagid="fd_3e59465a09231a.0.fd_3e59465b4a38ce" id="_xform_extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e59465b4a38ce)" property="extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e59465b4a38ce)" flagtype="xform_text" _xform_type="text"><input name="extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e59465b4a38ce)" subject="文本1" title="文本1" onblur="__xformDispatch(this.value, this);" class="inputsgl xform_inputText" value="" type="text" style="display: inline-block; width: 147px; word-break: break-all; overflow-wrap: break-word;width:120px;"> </xformflag> </div> <input name="extendDataFormInfo.value(fd_3e59465a09231a.0.fdId)" value="" type="hidden"> </td> <td class="" align="center" valign=""> <div style="display: inline-block; width: 202px;width: 210px;" class="xform_formula_load"> <xformflag flagid="fd_3e59465a09231a.0.fd_3e5946689e29d2" id="_xform_extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e5946689e29d2)" property="extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e5946689e29d2)" flagtype="formula_calculation" _xform_type="formulaCalculation"> <script> Com_IncludeFile('formula_calculation_script.js', '../sys/xform/designer/formula_calculation/'); </script> <script id="formula_calculation_script_js" src="/resource/../sys/xform/designer/formula_calculation/formula_calculation_script.js?s_cache=1754870647847"> </script> <input name="extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e5946689e29d2)" value="http://192.1.1.92:8080/webroot/decision/view/duchamp?viewlet=crm_project%252F%25E7%2589%25A9%25E6%2596%2599%25E4%25BE%259B%25E9%259C%2580%25E6%259F%25A5%25E8%25AF%25A2%25E9%25A1%25B5%25E9%259D%25A2.fvs&amp;ref_t=design&amp;ref_c=1e33972c-8151-43ff-81bb-d263b846af18&amp;page_number=1&amp;p_material=123" type="hidden" loadtype="autoLoad,manualLoad"><input name="extendDataFormInfo.value(fd_3e59465a09231a.0.fd_3e5946689e29d2_text)" subject="文本3" title="文本3" formula_calculation="true" isrow="true" returntype="text" loadtype="autoLoad,manualLoad" controlsid="fd_3e59465a09231a.fd_3e59465b4a38ce" fdid="fd_3e59465a09231a.0.fd_3e5946689e29d2" right="" readonly="readOnly" class="inputsgl xform_formula_load" value="" type="text" style="display: inline-block; width: 202px;width: 200px;"> </xformflag> </div> </td> <td class="" align="center" valign=""> <label class="xform_linkLabel" fd_type="linkLabel" style="display: inline-block; "><a target="_blank" href="www.baidu.com" style="color: rgb(66, 133, 244); font-weight: normal; font-style: normal; text-decoration: none;" parent_style="display: inline-block; width: 58px;" parent_class="xform_linkLabel">超链接1 </a></label> </td> <td class="" align="center" valign=""> <nobr><span style="cursor:pointer" class="optStyle opt_copy_style" title="复制行" onmousedown="DocList_CopyRow();"></span>  <span style="cursor:pointer" class="optStyle opt_del_style" title="删除行" onmousedown="DocList_DeleteRow_ClearLast();XFom_RestValidationElements();"></span>   </nobr> </td> </tr> <tr type="statisticRow" invalidrow="true"> <td row="1" column="0" align="center" coltype="selectCol" style="width: 15px;"></td> <td row="2" column="1" align="center" coltype="noFoot" style="width: 25px;"> </td> <td row="2" column="2" align="center"> </td> <td row="2" column="3" align="center"> </td> <td row="2" column="4" align="center"> </td> <td row="2" column="5" align="center" coltype="emptyCell" style="width: 48px;"> </td> </tr> <tr type="optRow" class="tr_normal_opt" invalidrow="true"> <td row="3" column="0" align="center" coltype="optCol" colspan="6" style=""> <div class="tr_normal_opt_content" style="min-width:580px;;"> <div class="tr_normal_opt_l"><label class="opt_ck_style" style="position:relative;top:3px;"><input type="checkbox" name="DocList_SelectAll" onclick="DocList_SelectAllRow(this);"><span style="margin-left: 6px;">全选<span></span></span></label><span style="margin-left:15px;" onclick="DocList_BatchDeleteRow();XFom_RestValidationElements();"><span class="optStyle opt_batchDel_style" style="margin-left:0px; " title="删除行"></span><span style="position:relative;top:3px;cursor: pointer;margin-left: 6px;">删除行</span></span> </div> <div class="tr_normal_opt_c"><span onclick="DocList_AddRow();XFom_RestValidationElements();"><span class="optStyle opt_add_style" title="添加行"></span><span style="position:relative;top:3px;cursor: pointer;margin-left: 6px;">添加行</span></span><span style="margin-left:15px;" onclick="DocList_MoveRowBySelect(-1);"><span class="optStyle opt_up_style" title="上移"></span><span style="position:relative;top:3px;cursor: pointer;margin-left: 6px;">上移</span></span><span style="margin-left:15px;" onclick="DocList_MoveRowBySelect(1);"><span class="optStyle opt_down_style" title="下移"></span><span style="position:relative;top:3px;cursor: pointer;margin-left: 6px;">下移</span></span> </div> <div class="tr_normal_opt_r"> </div> </div> </td> </tr> </tbody> </table> </td> </tr>
最新发布
08-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值