By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,766 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,766 IT Pros & Developers. It's quick & easy.

really basic question regarding arrays/function output...

P: n/a
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=hvm4MX4PXIY9J8C2Dcxz 5
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
Jul 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"bruce" <be*******@earthlink.netwrote in message
news:ma***************************************@pyt hon.org...
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 [i] (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
Jul 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.