really basic question regarding arrays/function output...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bruce

    #1

    really basic question regarding arrays/function output...

    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.ed u/ViewSections.as px?campus=CS&x= hvm4MX4PXIY9J8C 2Dcxz5
    0ncXTJdT7v2&typ e=M"

    f = urllib.urlopen( turl)
    s = f.read()
    f.close()
    # s contains HTML not XML text
    d = libxml2dom.pars eString(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


  • Paul McGuire

    #2
    Re: really basic question regarding arrays/function output...


    "bruce" <bedouglas@eart hlink.netwrote in message
    news:mailman.76 96.1151792861.2 7775.python-list@python.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


    Comment

    Working...