Python论坛  - 讨论区

标题:[python-chinese] 这是dict的用法吗?

2005年06月18日 星期六 18:23

ZeroSlug zyf_sz at tom.com
Sat Jun 18 18:23:22 HKT 2005

在《python scripting for computational science》里看到的这样的用法,这是字
典还是?
---
# data
compiler_data['GNU']['type'] = 'GNU 3.0'
compiler_data['GNU']['name'] = 'g77'
compiler_data['GNU']['options'] = '-Wall'
compiler_data['GNU']['libs'] = '-lf2c'
compiler_data['GNU']['test'] = '-Wall'
compiler_data['GNU']['flags'] = ('-O1','-O3','-O3 -funroll-loops')

for compiler in compiler_data:
c = compiler_data[compiler] # 'GNU', 'Sun', etc.
cmd = ' '.join([c['name'], c['options'], c['libs']])
for flag in c[flags]:
os.system(' '.join([cmd, flag, ' -o app ', files]))



[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年06月18日 星期六 19:26

limodou limodou at gmail.com
Sat Jun 18 19:26:13 HKT 2005

这是字典的用法呀。现在可以使用:
for i in d:
这种用法来遍历字典d的键值。有兴趣你自已可以试一试。

在 05-6-18,ZeroSlug<zyf_sz at tom.com> 写道:
> 在《python scripting for computational science》里看到的这样的用法,这是字
> 典还是?
> ---
> # data
> compiler_data['GNU']['type'] = 'GNU 3.0'
> compiler_data['GNU']['name'] = 'g77'
> compiler_data['GNU']['options'] = '-Wall'
> compiler_data['GNU']['libs'] = '-lf2c'
> compiler_data['GNU']['test'] = '-Wall'
> compiler_data['GNU']['flags'] = ('-O1','-O3','-O3 -funroll-loops')
> 
> for compiler in compiler_data:
> c = compiler_data[compiler] # 'GNU', 'Sun', etc.
> cmd = ' '.join([c['name'], c['options'], c['libs']])
> for flag in c[flags]:
> os.system(' '.join([cmd, flag, ' -o app ', files]))
> 
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 


-- 
I like python! 
My Donews Blog: http://www.donews.net/limodou
New Google Maillist: http://groups-beta.google.com/group/python-cn

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年06月18日 星期六 19:58

ZeroSlug zyf_sz at tom.com
Sat Jun 18 19:58:59 HKT 2005

sorry, 我意思是说前面的compiler_data部分

--------------------------------------------------------------------
# data
compiler_data['GNU']['type'] = 'GNU 3.0'
compiler_data['GNU']['name'] = 'g77'
compiler_data['GNU']['options'] = '-Wall'
compiler_data['GNU']['libs'] = '-lf2c'
compiler_data['GNU']['test'] = '-Wall'
compiler_data['GNU']['flags'] = ('-O1','-O3','-O3 -funroll-loops')
--------------------------------------------------------------------

在python2.3.4里面不能运行。 

字典不是类似 dict1={a:b,c:d,e:f} 这样定义的吗? 



limodou wrote:

>这是字典的用法呀。现在可以使用:
>for i in d:
>这种用法来遍历字典d的键值。有兴趣你自已可以试一试。
>
>在 05-6-18,ZeroSlug<zyf_sz at tom.com> 写道:
>  
>
>>在《python scripting for computational science》里看到的这样的用法,这是字
>>典还是?
>>---
>># data
>>compiler_data['GNU']['type'] = 'GNU 3.0'
>>compiler_data['GNU']['name'] = 'g77'
>>compiler_data['GNU']['options'] = '-Wall'
>>compiler_data['GNU']['libs'] = '-lf2c'
>>compiler_data['GNU']['test'] = '-Wall'
>>compiler_data['GNU']['flags'] = ('-O1','-O3','-O3 -funroll-loops')
>>
>>for compiler in compiler_data:
>>c = compiler_data[compiler] # 'GNU', 'Sun', etc.
>>cmd = ' '.join([c['name'], c['options'], c['libs']])
>>for flag in c[flags]:
>>os.system(' '.join([cmd, flag, ' -o app ', files]))
>>
>>
>>_______________________________________________
>>python-chinese list
>>python-chinese at lists.python.cn
>>http://python.cn/mailman/listinfo/python-chinese
>>
>>    
>>
>
>
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>  
>



[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年06月18日 星期六 20:04

limodou limodou at gmail.com
Sat Jun 18 20:04:04 HKT 2005

在 05-6-18,ZeroSlug<zyf_sz at tom.com> 写道:
> sorry, 我意思是说前面的compiler_data部分
> 
> --------------------------------------------------------------------
> # data
> compiler_data['GNU']['type'] = 'GNU 3.0'
> compiler_data['GNU']['name'] = 'g77'
> compiler_data['GNU']['options'] = '-Wall'
> compiler_data['GNU']['libs'] = '-lf2c'
> compiler_data['GNU']['test'] = '-Wall'
> compiler_data['GNU']['flags'] = ('-O1','-O3','-O3 -funroll-loops')
> --------------------------------------------------------------------
> 
> 在python2.3.4里面不能运行。
> 
> 字典不是类似 dict1={a:b,c:d,e:f} 这样定义的吗?
> 
字典是这样定义没错,但是字典的值可以还是一个字典呀,如:
a={}
a['GNU']={}
这样就可以:
a['GNU']['options'] = '-Wall'了
a['GNU']还可以写成一个对象,这个对象有__setitem__方法,可以用来摸拟a['item']这样的操作。方法很多的。
> 
> limodou wrote:
> 
> >这是字典的用法呀。现在可以使用:
> >for i in d:
> >这种用法来遍历字典d的键值。有兴趣你自已可以试一试。
> >
> >在 05-6-18,ZeroSlug<zyf_sz at tom.com> 写道:
> >
> >
> >>在《python scripting for computational science》里看到的这样的用法,这是字
> >>典还是?
> >>---
> >># data
> >>compiler_data['GNU']['type'] = 'GNU 3.0'
> >>compiler_data['GNU']['name'] = 'g77'
> >>compiler_data['GNU']['options'] = '-Wall'
> >>compiler_data['GNU']['libs'] = '-lf2c'
> >>compiler_data['GNU']['test'] = '-Wall'
> >>compiler_data['GNU']['flags'] = ('-O1','-O3','-O3 -funroll-loops')
> >>
> >>for compiler in compiler_data:
> >>c = compiler_data[compiler] # 'GNU', 'Sun', etc.
> >>cmd = ' '.join([c['name'], c['options'], c['libs']])
> >>for flag in c[flags]:
> >>os.system(' '.join([cmd, flag, ' -o app ', files]))
> >>
> >>
> >>_______________________________________________
> >>python-chinese list
> >>python-chinese at lists.python.cn
> >>http://python.cn/mailman/listinfo/python-chinese
> >>
> >>
> >>
> >
> >
> >
> >
> >------------------------------------------------------------------------
> >
> >_______________________________________________
> >python-chinese list
> >python-chinese at lists.python.cn
> >http://python.cn/mailman/listinfo/python-chinese
> >
> >
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 


-- 
I like python! 
My Donews Blog: http://www.donews.net/limodou
New Google Maillist: http://groups-beta.google.com/group/python-cn

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年06月18日 星期六 20:50

cpunion cpunion at 263.net
Sat Jun 18 20:50:12 HKT 2005

compiler_data = {'GNU':{ }}
compiler_data['GNU']['type'] = 'GNU 3.0'
......


compiler_data['GNU']也是一个字典,所以可以这样用。

ZeroSlug 写道:

>sorry, 我意思是说前面的compiler_data部分
>
>--------------------------------------------------------------------
># data
>compiler_data['GNU']['type'] = 'GNU 3.0'
>compiler_data['GNU']['name'] = 'g77'
>compiler_data['GNU']['options'] = '-Wall'
>compiler_data['GNU']['libs'] = '-lf2c'
>compiler_data['GNU']['test'] = '-Wall'
>compiler_data['GNU']['flags'] = ('-O1','-O3','-O3 -funroll-loops')
>--------------------------------------------------------------------
>
>在python2.3.4里面不能运行。 
>
>字典不是类似 dict1={a:b,c:d,e:f} 这样定义的吗? 
>
>
>
>limodou wrote:
>
>  
>
>>这是字典的用法呀。现在可以使用:
>>for i in d:
>>这种用法来遍历字典d的键值。有兴趣你自已可以试一试。
>>
>>在 05-6-18,ZeroSlug<zyf_sz at tom.com> 写道:
>> 
>>
>>    
>>
>>>在《python scripting for computational science》里看到的这样的用法,这是字
>>>典还是?
>>>---
>>># data
>>>compiler_data['GNU']['type'] = 'GNU 3.0'
>>>compiler_data['GNU']['name'] = 'g77'
>>>compiler_data['GNU']['options'] = '-Wall'
>>>compiler_data['GNU']['libs'] = '-lf2c'
>>>compiler_data['GNU']['test'] = '-Wall'
>>>compiler_data['GNU']['flags'] = ('-O1','-O3','-O3 -funroll-loops')
>>>
>>>for compiler in compiler_data:
>>>c = compiler_data[compiler] # 'GNU', 'Sun', etc.
>>>cmd = ' '.join([c['name'], c['options'], c['libs']])
>>>for flag in c[flags]:
>>>os.system(' '.join([cmd, flag, ' -o app ', files]))
>>>
>>>
>>>_______________________________________________
>>>python-chinese list
>>>python-chinese at lists.python.cn
>>>http://python.cn/mailman/listinfo/python-chinese
>>>
>>>   
>>>
>>>      
>>>
>> 
>>
>>------------------------------------------------------------------------
>>
>>_______________________________________________
>>python-chinese list
>>python-chinese at lists.python.cn
>>http://python.cn/mailman/listinfo/python-chinese
>> 
>>
>>    
>>
>
>
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>
>
>  
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年06月18日 星期六 21:06

ZeroSlug zyf_sz at tom.com
Sat Jun 18 21:06:11 HKT 2005

谢谢,字典可以多重嵌套呀,很方便。


cpunion wrote:

>compiler_data = {'GNU':{ }}
>compiler_data['GNU']['type'] = 'GNU 3.0'
>......
>
>
>compiler_data['GNU']也是一个字典,所以可以这样用。
>
>ZeroSlug 写道:
>
>  
>
>>sorry, 我意思是说前面的compiler_data部分
>>
>>--------------------------------------------------------------------
>># data
>>compiler_data['GNU']['type'] = 'GNU 3.0'
>>compiler_data['GNU']['name'] = 'g77'
>>compiler_data['GNU']['options'] = '-Wall'
>>compiler_data['GNU']['libs'] = '-lf2c'
>>compiler_data['GNU']['test'] = '-Wall'
>>compiler_data['GNU']['flags'] = ('-O1','-O3','-O3 -funroll-loops')
>>--------------------------------------------------------------------
>>
>>在python2.3.4里面不能运行。 
>>
>>字典不是类似 dict1={a:b,c:d,e:f} 这样定义的吗? 
>>
>>
>>
>>limodou wrote:
>>
>> 
>>
>>    
>>
>>>这是字典的用法呀。现在可以使用:
>>>for i in d:
>>>这种用法来遍历字典d的键值。有兴趣你自已可以试一试。
>>>
>>>在 05-6-18,ZeroSlug<zyf_sz at tom.com> 写道:
>>>
>>>
>>>   
>>>
>>>      
>>>
>>>>在《python scripting for computational science》里看到的这样的用法,这是字
>>>>典还是?
>>>>---
>>>># data
>>>>compiler_data['GNU']['type'] = 'GNU 3.0'
>>>>compiler_data['GNU']['name'] = 'g77'
>>>>compiler_data['GNU']['options'] = '-Wall'
>>>>compiler_data['GNU']['libs'] = '-lf2c'
>>>>compiler_data['GNU']['test'] = '-Wall'
>>>>compiler_data['GNU']['flags'] = ('-O1','-O3','-O3 -funroll-loops')
>>>>
>>>>for compiler in compiler_data:
>>>>c = compiler_data[compiler] # 'GNU', 'Sun', etc.
>>>>cmd = ' '.join([c['name'], c['options'], c['libs']])
>>>>for flag in c[flags]:
>>>>os.system(' '.join([cmd, flag, ' -o app ', files]))
>>>>
>>>>
>>>>_______________________________________________
>>>>python-chinese list
>>>>python-chinese at lists.python.cn
>>>>http://python.cn/mailman/listinfo/python-chinese
>>>>
>>>>  
>>>>
>>>>     
>>>>
>>>>        
>>>>
>>>------------------------------------------------------------------------
>>>
>>>_______________________________________________
>>>python-chinese list
>>>python-chinese at lists.python.cn
>>>http://python.cn/mailman/listinfo/python-chinese
>>>
>>>
>>>   
>>>
>>>      
>>>
>>_______________________________________________
>>python-chinese list
>>python-chinese at lists.python.cn
>>http://python.cn/mailman/listinfo/python-chinese
>>
>>
>> 
>>
>>    
>>
>_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>
>
>  
>



[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号