How do I access what's in this module?

F

Fencer

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: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
 
J

John Machin

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
 
F

Fencer

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
 
J

John Machin

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 :)
 
F

Fencer

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. :)
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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top