[lxml-dev] could not find doctest
Mary Lei
lei at ipac.caltech.edu
Wed May 20 20:06:36 CEST 2009
I discovered the following for my purpose:
---------------------------------------
import lxml.html
## html output
html = lxml.html.fromstring('''\
<html><body onload="" color="white">
Creating HTML with the E-factory
<p>Hi !</p>
</body></html>
''')
print lxml.html.tostring(html)
#<html><body onload="" color="white"><p>Hi !</p></body></html>
print lxml.html.tostring(html)
from lxml.html import builder as E
html = E.HTML(
E.HEAD(
# E.LINK(rel="stylesheet", href="great.css", type="text/css"),
E.TITLE("Best Page Ever")
),
E.BODY(
E.H1(E.CLASS("heading"), "Top News"),
E.P("World News only on this page", style="font-size: 200%"),
"Ah, and here's some more text, by the way.",
lxml.html.fromstring("<p> and this is a parsed fragment </p>")
)
)
print lxml.html.tostring(html,pretty_print=True) <-- is what I want
------------------------------------------
but got confused by doctest yesterday, being new to python.
Stefan Behnel wrote:
> Mary Lei wrote:
>> I copied the following from the lxml document on the web:
>
> ... and you copied a bit too much.
>
>> from lxml.html import usedoctest
>>
>> Traceback (most recent call last):
>> File "/home/lei/lxml-2.2/src/lxml/doctestcompare.py", line 486, in
>> _find_doctest_frame
>> "Could not find doctest (only use this function *inside* a doctest)")
>> LookupError: Could not find doctest (only use this function *inside* a
>> doctest)
>
> As the error message tells you, importing "usedoctest" will only work from
> a doctest. Unless you are writing a doctest, there is no reason to use
> that module.
>
> Stefan
--
Mary Lei
Software Testing
IPAC-NExScl
Rm: KS-233
MS: 220-6
Phone: 395-1998
More information about the lxml-dev
mailing list