really basic question regarding arrays/function output...

B

bruce

hi...

i have the following test python script.... i'm trying to figure out a
couple of things...

1st.. how can i write the output of the "label" to an array, and then how i
can select a given element of the array.. i know real basic..

2nd.. where can i go to find methods of libxml2dom. i've been looking using
google, but can't seem to find a site pointing out the underlying methods,
which is kind of strange...

-bruce



-------------------------------------
test.py
#! /usr/bin/env python

#test python script
import libxml2dom
import urllib

print "hello"

turl =
"http://courses.tamu.edu/ViewSections.aspx?campus=CS&x=hvm4MX4PXIY9J8C2Dcxz5
0ncXTJdT7v2&type=M"

f = urllib.urlopen(turl)
s = f.read()
f.close()
# s contains HTML not XML text
d = libxml2dom.parseString(s, html=1)
# get the community-related links
for label in
d.xpath("/html/body/table/tr/td[2]/table/tr[6]/td/table/child::tr/td[@class=
'sectionheading']/text()"):

print label.nodeValue
 
P

Paul McGuire

bruce said:
hi...

i have the following test python script.... i'm trying to figure out a
couple of things...

1st.. how can i write the output of the "label" to an array, and then how i
can select a given element of the array.. i know real basic..
I think this is so basic, I'm not sure what you're talking about. One does
not really "write to an array". In fact, Python's most natural data
structure is a list, which has many array-like features (there is also an
array module, but since you are asking basic questions, I'm trying to stick
to basic Python).

To append an item to a list, use append.
To graft one list on to the end of another, use += or extend.
To access the i'th element of a list use (indices are zero-based).

This is covered in far better detail in the Python tutorials. These
fundamental data structures of Python (list, tuple, dict, set, str) are your
fundamental tools when writing Python code, so you should read up on them.
2nd.. where can i go to find methods of libxml2dom. i've been looking using
google, but can't seem to find a site pointing out the underlying methods,
which is kind of strange...
Try dir and help from the Python interactive command line. Assuming you
have installed libxml2dom, do this:

import libxml2dom
dir(libxml2dom)
help(libxml2dom)

I see that this module also contains directories for tests and tools, these
may provide you with some usage examples. (The docs directory *is* woefully
brief...)

-- Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top