473,788 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2086
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(re pr,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

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

Similar topics

2
3427
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 displays, it goes 'behind' combo box (sent to back). For other controls, like textbox, it is fine. Can some explain, how can I send the list box (<asp:listbox>) to become the underneath and not display on top? Alwin S.
13
40767
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 style="display:none"> can be displayed by setting the style attribute to "display:", or hidden with "display:none". This gives the illusion that the person filling out the form is switching from page to page...without the overhead of extra hits on the server,...
7
4686
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: block for the link adds a bit of whitespace between the list items. NS7.1 does not do this. Why the whitespace (about 5px)? Is it possible to get IE and NS looking
10
13462
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 related to checkboxes. Thanks!!!
19
6933
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 JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the page....Take a look at the JavaScript code and please let me know what each line is doing....I have been...
3
18589
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 still exists in the code). Is there an equivalent in IE? The reasoning behind this is that I want users to rank objects using a <select> for each place (see below), and to remove the choice of earlier objects from <select> drop-downs later in the...
7
6061
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 there any other way to display/undisplay parts of web pages? TIA
0
1958
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 of string manipulation where they seek through the string back and forth doing replacements to substitute in the needed HTML code. I am convinced that this can be done with a few regular expressions. Unfortunately my knowledge of regular...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.