How do I access what's in this module?

Discussion in 'Python' started by Fencer, Jan 8, 2010.

  1. Fencer

    Fencer Guest

    Hello, look at this lxml documentation page:
    http://codespeak.net/lxml/api/index.html

    How do I access the functions and variables listed?

    I tried from lxml.etree import ElementTree and the import itself seems
    to pass without complaint by the python interpreter but I can't seem to
    access anything in ElementTree, not the functions or variables. What is
    the proper way to import that module?

    For example:
    >>> from lxml.etree import ElementTree
    >>> ElementTree.dump(None)

    Traceback (most recent call last):
    File "<console>", line 1, in <module>

    Also, can I access those items that begin with an underscore if I get
    the import sorted?

    - Fencer
     
    Fencer, Jan 8, 2010
    #1
    1. Advertising

  2. Fencer

    John Machin Guest

    On Jan 8, 12:21 pm, Fencer <>
    wrote:
    > Hello, look at this lxml documentation page:http://codespeak.net/lxml/api/index.html


    That's for getting details about an object once you know what object
    you need to use to do what. In the meantime, consider reading the
    tutorial and executing some of the examples:
    http://codespeak.net/lxml/tutorial.html

    > How do I access the functions and variables listed?
    >
    > I tried from lxml.etree import ElementTree and the import itself seems
    > to pass without complaint by the python interpreter but I can't seem to
    > access anything in ElementTree, not the functions or variables. What is
    > the proper way to import that module?
    >
    > For example:
    >  >>> from lxml.etree import ElementTree
    >  >>> ElementTree.dump(None)
    > Traceback (most recent call last):
    >    File "<console>", line 1, in <module>


    lxml.etree is a module. ElementTree is effectively a class. The error
    message that you omitted to show us might have given you a clue.

    To save keystrokes you may like to try
    from lxml import etree as ET
    and thereafter refer to the module as "ET"

    | >>> from lxml import etree as ET
    | >>> type(ET)
    | <type 'module'>
    | >>> type(ET.ElementTree)
    | <type 'builtin_function_or_method'>
    | >>> help(ET.ElementTree)
    | Help on built-in function ElementTree in module lxml.etree:
    |
    | ElementTree(...)
    | ElementTree(element=None, file=None, parser=None)
    |
    | ElementTree wrapper class.

    > Also, can I access those items that begin with an underscore if I get
    > the import sorted?


    Using pommy slang like "sorted" in an IT context has the potential to
    confuse your transatlantic correspondents :)

    Can access? Yes. Should access? The usual Python convention is that an
    object whose name begins with an underscore should be accessed only
    via a documented interface (or, at your own risk, if you think you
    know what you are doing).

    HTH,
    John
     
    John Machin, Jan 8, 2010
    #2
    1. Advertising

  3. Fencer

    Fencer Guest

    On 2010-01-08 04:40, John Machin wrote:

    >>
    >> For example:
    >> >>> from lxml.etree import ElementTree
    >> >>> ElementTree.dump(None)

    >> Traceback (most recent call last):
    >> File "<console>", line 1, in<module>

    >
    > lxml.etree is a module. ElementTree is effectively a class. The error
    > message that you omitted to show us might have given you a clue.


    But I did show the error message? It's just above what you just wrote. I
    try to include all relevant information in my posts.

    >
    > Using pommy slang like "sorted" in an IT context has the potential to
    > confuse your transatlantic correspondents :)


    Ah, of course! :)

    >
    > Can access? Yes. Should access? The usual Python convention is that an
    > object whose name begins with an underscore should be accessed only
    > via a documented interface (or, at your own risk, if you think you
    > know what you are doing).


    It turns out I no longer want to access anything in there but I thank
    you for your information nontheless.

    >
    > HTH,
    > John


    - Fencer
     
    Fencer, Jan 8, 2010
    #3
  4. Fencer

    John Machin Guest

    On Jan 8, 2:45 pm, Fencer <>
    wrote:
    > On 2010-01-08 04:40, John Machin wrote:
    >
    >
    >
    > >> For example:
    > >>   >>>  from lxml.etree import ElementTree
    > >>   >>>  ElementTree.dump(None)
    > >> Traceback (most recent call last):
    > >>     File "<console>", line 1, in<module>

    >
    > > lxml.etree is a module. ElementTree is effectively a class. The error
    > > message that you omitted to show us might have given you a clue.

    >
    > But I did show the error message? It's just above what you just wrote. I
    > try to include all relevant information in my posts.


    <excerpt>
    Traceback (most recent call last):
    File "<console>", line 1, in <module>

    Also, can I access those items ...
    </excerpt>

    Error message should appear after line starting with "File". Above
    excerpt taken from google groups; identical to what shows in
    http://news.gmane.org/gmane.comp.python.general ... what are you
    looking at?

    With Windows XP and Python 2.5.4 I get:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'builtin_function_or_method' object has no attribute
    'dump'

    > It turns out I no longer want to access anything in there but I thank
    > you for your information nontheless.


    You're welcome -- the advice on _methods is portable :)
     
    John Machin, Jan 8, 2010
    #4
  5. Fencer

    Fencer Guest

    On 2010-01-08 05:01, John Machin wrote:
    >
    > Error message should appear after line starting with "File". Above
    > excerpt taken from google groups; identical to what shows in
    > http://news.gmane.org/gmane.comp.python.general ... what are you
    > looking at?
    >
    > With Windows XP and Python 2.5.4 I get:
    >
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in<module>
    > AttributeError: 'builtin_function_or_method' object has no attribute
    > 'dump'


    I'm sorry, I managed to leave out that last line by mistake! My bad. I
    didn't spot that in my first reply to you because I was under the
    impression that you hadn't seen the tiniest part of traceback. As you
    neatly pointed out earlier, it's easy to become confused when
    communicating. :)
    >
    >> It turns out I no longer want to access anything in there but I thank
    >> you for your information nontheless.

    >
    > You're welcome -- the advice on _methods is portable :)


    I will look more closely at what other advice you write, I must confess
    I didn't actually do that because, as I mentioned, I no longer had any
    interest in accessing the module and I was busy (and still am) with
    another problem. Thanks John!

    - Fencer
     
    Fencer, Jan 8, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    2
    Views:
    539
    Wade A. Hilmo [MS]
    Nov 29, 2003
  2. eric_bellard
    Replies:
    1
    Views:
    5,112
    CarlosRivera
    Oct 7, 2004
  3. Maric Michaud
    Replies:
    0
    Views:
    7,194
    Maric Michaud
    Jun 24, 2006
  4. abcd
    Replies:
    4
    Views:
    244
    Ben Finney
    Mar 20, 2007
  5. Gabriel Genellina
    Replies:
    0
    Views:
    445
    Gabriel Genellina
    Nov 21, 2008
Loading...

Share This Page