首页 新闻 会员 周边 捐助

IronPython 数据格式

0
悬赏园豆:80 [已关闭问题]
我在看IronPython的时候,看到一种数据存储类型,不知道是什么东东。。到处找资料也找不到。<br>源码来自微软的IronPython网站,eg:<br><div class="cnblogs_code"><img src="/Images/OutliningIndicators/ContractedBlock.gif" id="Code_Closed_Image_080646" onclick="this.style.display='none'; Code_Closed_Text_080646.style.display='none'; Code_Open_Image_080646.style.display='inline'; Code_Open_Text_080646.style.display='inline';" width="11" align="top" height="16"><img src="/Images/OutliningIndicators/ExpandedBlockStart.gif" id="Code_Open_Image_080646" style="display: none;" onclick="this.style.display='none'; Code_Open_Text_080646.style.display='none'; Code_Closed_Image_080646.style.display='inline'; Code_Closed_Text_080646.style.display='inline';" width="11" align="top" height="16"><span id="Code_Closed_Text_080646" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255);">Code</span><span id="Code_Open_Text_080646" style="display: none;"><br><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);">1</span><img src="/Images/OutliningIndicators/None.gif" align="top"><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">:<br></span><span style="color: rgb(0, 128, 128);">2</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;cmd.ExecuteReader()<br></span><span style="color: rgb(0, 128, 128);">3</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;[]<br></span><span style="color: rgb(0, 128, 128);">4</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">&nbsp;reader.Read():<br></span><span style="color: rgb(0, 128, 128);">5</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fields&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;dict([(reader.GetName(i),&nbsp;reader.GetValue(i))&nbsp;</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">&nbsp;range(reader.FieldCount)])<br></span><span style="color: rgb(0, 128, 128);">6</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result.append(DB.__DataRow(fields))<br></span><span style="color: rgb(0, 128, 128);">7</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;result<br></span><span style="color: rgb(0, 128, 128);">8</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">finally</span><span style="color: rgb(0, 0, 0);">:<br></span><span style="color: rgb(0, 128, 128);">9</span><span style="color: rgb(0, 0, 0);"><img src="/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;reader:&nbsp;reader.Close()</span></span></div> 代码中的这句:<br><div class="cnblogs_code"><span style="color: rgb(0, 0, 0);">dict([(reader.GetName(i),&nbsp;reader.GetValue(i))&nbsp;</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">&nbsp;i&nbsp;</span><span style="color: rgb(0, 0, 255);">in</span><span style="color: rgb(0, 0, 0);">&nbsp;range(reader.FieldCount)])<br>dict感觉是一个函数,又不是很像,完整的代码返回的数据是data([list]),我不知道这个是什么类型的数据,更不知道怎么转换处理,请高手找指教。。<br></span></div>
聽雨的主页 聽雨 | 初学一级 | 园豆:30
提问于:2008-07-31 08:08
< >
分享
其他回答(1)
0
看起来应该是一种类似dictionary的类型
丁学 | 园豆:18730 (专家六级) | 2008-08-01 17:16
0
就是哈希类型,里面使用了generator tel={'key1':4098,'k2',1111} python中dict比较灵活可以做为queue,还有stack来用
lexus | 园豆:0 (初学一级) | 2008-08-03 13:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册