-
- PowerShell将配置文件转换为字典(hash table)
- 2012-11-10
标准的*nix下的配置文件一般是如下的标准格式
#this is a test conf file [SectionName1] name=abc id=123 [dbinfo] db=localhost name=testdb user=root
因此我们在很多应用时也采用这种方式,简单易理解,维护也方便,但是在程序用需要将里面的内容转化为程序能使用的更高效的字典才能真正发挥作用,如果是python的话,可以直接用configParser,
而对于Windows上使用的PowerShell,这种“外来”的和尚,想要能念得起经,还是要自己动手的
- Views(6660) | Comments(0) | In System/Application
-
- Python中字典操作的常用方法
- Weather:13~23度,西南风4~5级,晴
- 2009-05-05
当然说字典,那也就有一些常用方法
------------------------清除------------------------
clear()方法,将字典所有内容清除:
>>> d = {'age' : 12, 'name' : 'bob'}
>>> d
{'age': 12, 'name': 'bob'}
>>> d.clear()
>>> d
{}
有人可能会问为什么不直接d={}?
看下面的例子:
>>> d = {'age' : 12, 'name' : 'bob'}
>>> x = d
>>> d = {}
>>> x
{'age': 12, 'name': 'bob'}.....- Views(6591) | Comments(0) | In Python相关
-
- Python下为字典排序
- Weather:阴 ,东南风 4-5级 ,最低气温4 ℃
- 2006-04-03
<p># (IMHO) the simplest approach:<br /> def sortedDictValues1(adict):<br /> items = adict.items()<br /> items.sort()<br /> return [value for key, value in items]<br /> <br /> # an alternative implementation, which<br /> # happens to run a bit faster for large<br /> # dictionaries on my machine:<br /> def sortedDictValues2(adict):<br /> ...</p>
- Views(5332) | Comments(0) | In Python相关
