472,364 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

How to display name of elements in list?

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

Jul 12 '06 #1
13 1926
Ant
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)
I presume this is the same in 1.5 use dir():
>>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',

(etc)

Jul 12 '06 #2
On Wed, 12 Jul 2006 05:17:30 -0700, cz wrote:
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.
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.

Jul 12 '06 #3
cz
Perhaps you need to rephrase your question.
--
Steven.
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
I will get "1" as an answer.
Or with
>>print elten[1].intensity
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

Jul 12 '06 #4
Hi Claudio,

cz wrote:
>Perhaps you need to rephrase your question.
--
Steven.

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
I will get "1" as an answer.
Or with
>>print elten[1].intensity
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?
The list above is not a valid Python list. What is it that you store in that list?

Or is it maybe a dictionary?

Stefan
Jul 12 '06 #5
cz
The list above is not a valid Python list. What is it that you store in that list?
>
Or is it maybe a dictionary?

Stefan
Thanks for your help. How can I find out about what this is? As I said
it's generated by a insufficiently documented module. So if this is a
user defined datatype, is there still a possibility to find the name of
the data fields storing the xx, xy, ... ?
Thanks.

Jul 12 '06 #6
cz wrote:
>The list above is not a valid Python list. What is it that you store in
that list?

Or is it maybe a dictionary?

Stefan

Thanks for your help. How can I find out about what this is? As I said
it's generated by a insufficiently documented module. So if this is a
user defined datatype, is there still a possibility to find the name of
the data fields storing the xx, xy, ... ?
I guess the objects stored in the list have a __repr__-method overloaded
that produces the text you see.

What you should do is to install rlcompleter2, fire up a python prompt and
write code that produces a list of your objects. Then you can play around
with the objects and utilize the reflection capabilities of python, which
are conveniently exposed using rlcompleter2.

Another option is to look into the source of that module and identify the
objects created. Documentation is overrated - use the source, Luke!

Diez
Jul 12 '06 #7
>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
]
The list above is not a valid Python list. What is it that you store in that list?
It might well be a normal Python list.

The question is what type the items in the list are...
The result of printing a list L is basically a string you
could make like this:

'[' + ','.join(map(repr,L)) + ']'

It seems the elements in this list appear as something
like this when you apply the repr() function on them:

Tensor: id = 1, intensity = 2976.52
xx = -1447.32, xy = 52.458, xz = -594.186
yy = -1090.54, yz = -0.0158068, zz = -4043.

So, the issue is not how you work with a list,
but how you work with the elements of this type.

To reduce the problem to that, you can assign the
first element in the list to a variable.

elem0 = elten[0]

Then you can inspect that in isolation, without
the confusion of the list.

type(elem0)
dir(elem0)
etc...
Jul 12 '06 #8
cz schrieb:
>The list above is not a valid Python list. What is it that you store in that list?

Or is it maybe a dictionary?

Stefan

Thanks for your help. How can I find out about what this is? As I said
it's generated by a insufficiently documented module. So if this is a
user defined datatype, is there still a possibility to find the name of
the data fields storing the xx, xy, ... ?
Maybe you should read a bit about Python classes and built-in functions like
"dir()", "type()", "vars()", ...

http://docs.python.org/tut/node8.htm...00000000000000
http://docs.python.org/tut/node11.html
http://docs.python.org/lib/built-in-funcs.html

Just start an interactive Python session and play with the object you are
trying to explore. That should get you going.

Stefan
Jul 12 '06 #9
Stefan Behnel wrote:
The list above is not a valid Python list.
there's no Python 1.5.3 either. maybe he's posting from a parallel,
slightly different universe ?

</F>

Jul 12 '06 #10
Diez B. Roggisch <deets <atnospam.web.dewrites:
>
What you should do is to install rlcompleter2...
[snip]
>
Another option is to look into the source of that module and identify the
objects created. Documentation is overrated - use the source, Luke!
rlcompleter is overrated, and only works on Unix/Linux/etc.

IDLE's interpreter has an auto-completion extension, which is bundled in
Python2.5.

You can also get a much better version of IDLE which includes a more robust
version of the completion extension from Idle-Spoon:
http://idlespoon.python-hosting.com/
stefan writes:
>
Just start an interactive Python session and play with the object you are
trying to explore. That should get you going.
+1
Python is fun - just open an interpreter and play around!
- Tal

Jul 12 '06 #11
rlcompleter is overrated, and only works on Unix/Linux/etc.
>
IDLE's interpreter has an auto-completion extension, which is bundled in
Python2.5.
I don't use idle, and don't want to. So for me rlcomlpeter2 is a good thing.
And under windows, it at least works under cygwin.

Diez

Jul 12 '06 #12
Pretty sure he meant 1.5.1.

Found the documentation for the program he's using here:
http://www.hpcu.uq.edu.au/Manuals/MS...hon_manual.pdf
It looks like the PyTensor object *should* have .xx, .xy, etc
properties, but they may be accessible through a matrix, i.e. .t(i,j)

Jul 12 '06 #13
cz

ru*****@gmail.com wrote:
It looks like the PyTensor object *should* have .xx, .xy, etc
properties, but they may be accessible through a matrix, i.e. .t(i,j)

Thanks to all of you for your help!
The solution is easy: The tensor components have labels t11, t12,...
Good guess ruibalp!

Jul 27 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Al Sav | last post by:
Hi, I am trying to create a menu for asp.net page. The menu-detail list display, when mouse hovers over the main menu list, like you see in regular windows apps. When the detail-menu-list window...
13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
7
by: Jeff Thies | last post by:
I'm trying to do a nav list using list items. Roughly this is putting links styled display: block and with a background color. In IE5 (windows, haven't tried Mac yet), adding the display:...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
3
by: Iain Hallam | last post by:
Hi. I've been using display:none on the style property of some <option> elements in my forms, which works fine with Mozilla - as expected it removes the option from my dropdown (although it...
7
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is...
0
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.