如何在列表中显示元素的名称? [英] How to display name of elements in list?
问题描述
你好,
我确定我的问题有一个非常简单的解决方案,我只是没有
找到它到现在。
我正在使用一个记录严密的模块,因此需要找出
关于如何访问列表中的元素。
(我需要在Python 1.5.3中这样做)
非常感谢任何帮助。谢谢!
cz
Hi there,
I''m sure there is a very simple solution for my question, I just didn''t
find it up to now.
I''m using a badly documented module and therefore need to find out
about how to access the elements in a list.
(I need to do this in Python 1.5.3)
Any help appreciated very much. Thanks!
cz
推荐答案
我正在使用记录严密的模块和因此需要找出
I''m using a badly documented module and therefore need to find out
关于如何访问列表中的元素。
(我需要在Python 1.5.3中这样做) )
about how to access the elements in a list.
(I need to do this in Python 1.5.3)
我认为这与1.5使用dir()相同:
I presume this is the same in 1.5 use dir():
>> import os
dir(os)
>>import os
dir(os)
[''F_OK'',''O_APPEND'',''O_BINARY'',''O_CREAT'',''O_EXCL'',''O_NOINHERIT'',
''O_RANDOM'' ,
''O_RDONLY'',''O_RDWR'',''O_SEQUENTIAL'',''O_SHORT_LIVED'',''O_TEMPORARY'',
''O_TEXT '',
(等)
[''F_OK'', ''O_APPEND'', ''O_BINARY'', ''O_CREAT'', ''O_EXCL'', ''O_NOINHERIT'',
''O_RANDOM'',
''O_RDONLY'', ''O_RDWR'', ''O_SEQUENTIAL'', ''O_SHORT_LIVED'', ''O_TEMPORARY'',
''O_TEXT'',
(etc)
2006年7月12日星期三05:17 :30 -0700,cz写道:
On Wed, 12 Jul 2006 05:17:30 -0700, cz wrote:
你好,
我肯定有一个非常简单的解决方案对于我的问题,我刚才没有找到它。$ / b
我正在使用一个记录严密的模块,因此需要找出
关于如何访问列表中的元素。
Hi there,
I''m sure there is a very simple solution for my question, I just didn''t
find it up to now.
I''m using a badly documented module and therefore need to find out
about how to access the elements in a list.
呃,就像访问任何其他列表中的元素一样?
mylist [0]
mylist [1:5]
也许你需要改写你的问题。
- -
史蒂文。
Er, the same way you would access the elements in any other list?
mylist[0]
mylist[1:5]
etc.
Perhaps you need to rephrase your question.
--
Steven.
也许你需要重新解释你的问题。
-
史蒂文。
Perhaps you need to rephrase your question.
--
Steven.
感谢您的回复。
好的,我会尽量让这个更清楚:
我的名单叫做elten看起来像这样:
[张量:id = 1,强度= 2976.52
xx = -1447.32,xy = 52.458,xz = -594.186 >
yy = -1090.54,yz = -0.0158068,zz = -4043。
,张量:id = 26,强度= 2896.9
...
,Tensor:id = 5,强度= 2920.5
xx = -1534.53,xy = 23.4858,xz = -623.967
yy = -1070.47 ,yz = 99.6301,zz = -3979.87
]
现在使用
Thanks for your reply.
OK, I''ll try to make this more clear:
My list called "elten" looks like that:
[Tensor: id = 1, intensity = 2976.52
xx = -1447.32, xy = 52.458, xz = -594.186
yy = -1090.54, yz = -0.0158068, zz = -4043.
, Tensor: id = 26, intensity = 2896.9
...
, Tensor: id = 5, intensity = 2920.5
xx = -1534.53, xy = 23.4858, xz = -623.967
yy = -1070.47, yz = 99.6301, zz = -3979.87
]
Now with
>> print elten [1] .id
>>print elten[1].id
我将得到1作为答案。
或者
I will get "1" as an answer.
Or with
>> print elten [1] .intensity
>>print elten[1].intensity
它将打印2976.52。
但这不适用于>> print elten [1] .xx,为什么?这就是我如何获得如何获取这些价值的问题。不知道吗?
非常感谢!
cz
it will print "2976.52".
But this doesn''t work for >>print elten[1].xx, why? So that''s how I
came to the question how to access these values. Any idea?
Thanks a lot!
cz
这篇关于如何在列表中显示元素的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!