Re: ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread fronagzen
On Thursday, July 11, 2013 8:25:13 PM UTC+8, F.R. wrote: > On 07/11/2013 10:59 AM, F.R. wrote: > > > Hi all, > > > > > > I haven't been able to get up to speed with XML. I do examples from > > > the tutorials and experiment with variations. Time and time again I > > > fail with errors messag

Re: ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread F.R.
On 07/11/2013 10:59 AM, F.R. wrote: Hi all, I haven't been able to get up to speed with XML. I do examples from the tutorials and experiment with variations. Time and time again I fail with errors messages I can't make sense of. Here's the latest one. The url is "http://finance.yahoo.com/q?s=

Re: ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread Fábio Santos
On 11 Jul 2013 10:24, wrote: > > Actually, I don't think etree has a HTML parser. And I would counter-recommend lxml if speed is an issue: BeautifulSoup takes a long time to parse a large document. > > On Thursday, July 11, 2013 5:08:04 PM UTC+8, Fábio Santos wrote: > > > > Use an HTML parser.

Re: ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread fronagzen
Actually, I don't think etree has a HTML parser. And I would counter-recommend lxml if speed is an issue: BeautifulSoup takes a long time to parse a large document. On Thursday, July 11, 2013 5:08:04 PM UTC+8, Fábio Santos wrote: > On 11 Jul 2013 10:04, "F.R." wrote: > > > > > > Hi all, >

Re: ElementTree: can't figure out a mismached-tag error

2013-07-11 Thread Fábio Santos
On 11 Jul 2013 10:04, "F.R." wrote: > > Hi all, > > I haven't been able to get up to speed with XML. I do examples from the tutorials and experiment with variations. Time and time again I fail with errors messages I can't make sense of. Here's the latest one. The url is " http://finance.yahoo.com/

Re: ElementTree Issue - Search and remove elements

2012-10-17 Thread Stefan Behnel
Alain Ketterlin, 17.10.2012 08:25: > It looks like you can't get the parent of an Element with elementtree (I > would love to be proven wrong on this). No, that's by design. ElementTree allows you to reuse subtrees in a document, for example, which wouldn't work if you enforced a single parent. Al

Re: ElementTree Issue - Search and remove elements

2012-10-16 Thread Alain Ketterlin
Tharanga Abeyseela writes: > I need to remove the parent node, if a particular match found. It looks like you can't get the parent of an Element with elementtree (I would love to be proven wrong on this). The solution is to find all nodes that have a Rating (grand-) child, and then test explici

Re: ElementTree Issue - Search and remove elements

2012-10-16 Thread Stefan Behnel
Hi, note that it's best to reply to responses you get, rather than starting a new thread on the same topic. It helps in building up context and in keeping details together at one point in the archive for users who run into similar problems later. Tharanga Abeyseela, 17.10.2012 07:47: > I need to

Re: ElementTree XML parsing problem

2011-04-27 Thread Ervin Hegedüs
hello, On Thu, Apr 28, 2011 at 07:57:28AM +0200, Stefan Behnel wrote: > >So, I started change the codepage mark of xml: > > > > - same result > > - same result > > - same result > > You probably changed this in an editor that supports XML and thus > saves the file in the declared encoding. no

Re: ElementTree XML parsing problem

2011-04-27 Thread Stefan Behnel
Hegedüs Ervin, 27.04.2011 21:33: hello, I'm using ElementTree to parse an XML file, but it stops at the second record (id = 002), which contains a non-standard ascii character, ä. Here's the XML: The complaint offered up by the parser is I've checked this xml with your script, I thi

Re: ElementTree XML parsing problem

2011-04-27 Thread Mike
On 4/27/2011 12:24 PM, Neil Cerutti wrote: On 2011-04-27, Mike wrote: I'm using ElementTree to parse an XML file, but it stops at the second record (id = 002), which contains a non-standard ascii character, ?. Here's the XML: The complaint offered up by the parser is Unexpected error

Re: ElementTree XML parsing problem

2011-04-27 Thread Mike
On 4/27/2011 12:33 PM, Hegedüs Ervin wrote: hello, I'm using ElementTree to parse an XML file, but it stops at the second record (id = 002), which contains a non-standard ascii character, ä. Here's the XML: The complaint offered up by the parser is I've checked this xml with your sc

Re: ElementTree XML parsing problem

2011-04-27 Thread Hegedüs Ervin
hello, > I'm using ElementTree to parse an XML file, but it stops at the > second record (id = 002), which contains a non-standard ascii > character, ä. Here's the XML: > > > > > > > > > > > The complaint offered up by the parser is I've checked this xml with your script, I think your l

Re: ElementTree XML parsing problem

2011-04-27 Thread Philip Semanchuk
On Apr 27, 2011, at 2:26 PM, Mike wrote: > I'm using ElementTree to parse an XML file, but it stops at the second record > (id = 002), which contains a non-standard ascii character, ä. Here's the XML: > > > > > > > > > > > The complaint offered up by the parser is > > Unexpected error

Re: ElementTree XML parsing problem

2011-04-27 Thread Neil Cerutti
On 2011-04-27, Mike wrote: > I'm using ElementTree to parse an XML file, but it stops at the > second record (id = 002), which contains a non-standard ascii > character, ?. Here's the XML: > > > > > > > > > > > The complaint offered up by the parser is > > Unexpected error opening simple_fail.xml:

Re: ElementTree XML parsing problem

2011-04-27 Thread Benjamin Kaplan
On Wed, Apr 27, 2011 at 2:26 PM, Mike wrote: > I'm using ElementTree to parse an XML file, but it stops at the second > record (id = 002), which contains a non-standard ascii character, ä. Here's > the XML: > > > > > > > > > > > The complaint offered up by the parser is > > Unexpected erro

Re: ElementTree handling nested tag

2010-10-04 Thread Diez B. Roggisch
tekion writes: > On Oct 3, 2:09 pm, de...@web.de (Diez B. Roggisch) wrote: >> tekion writes: >> > On Oct 2, 5:32 am, de...@web.de (Diez B. Roggisch) wrote: >> >> tekion writes: >> >> > All, >> >> > I have the following xml tag: >> >> > >> >> > >> >> >       httpRequest >> >> >       HTTP://cm

Re: ElementTree handling nested tag

2010-10-03 Thread tekion
On Oct 3, 2:09 pm, de...@web.de (Diez B. Roggisch) wrote: > tekion writes: > > On Oct 2, 5:32 am, de...@web.de (Diez B. Roggisch) wrote: > >> tekion writes: > >> > All, > >> > I have the following xml tag: > >> > > >> > > >> >       httpRequest > >> >       HTTP://cmd.wma.ibm.com:80/ > >> >    

Re: ElementTree handling nested tag

2010-10-03 Thread Diez B. Roggisch
tekion writes: > On Oct 2, 5:32 am, de...@web.de (Diez B. Roggisch) wrote: >> tekion writes: >> > All, >> > I have the following xml tag: >> > >> > >> >       httpRequest >> >       HTTP://cmd.wma.ibm.com:80/ >> >       GET >> >       200 >> >     >> > >> >> > I am interested in: >> >        

Re: ElementTree handling nested tag

2010-10-03 Thread tekion
On Oct 2, 5:32 am, de...@web.de (Diez B. Roggisch) wrote: > tekion writes: > > All, > > I have the following xml tag: > > > > > >       httpRequest > >       HTTP://cmd.wma.ibm.com:80/ > >       GET > >       200 > >     > > > > > I am interested in: > >        httpRequest > >       HTTP://cmd.

Re: ElementTree handling nested tag

2010-10-02 Thread Diez B. Roggisch
tekion writes: > All, > I have the following xml tag: > > > httpRequest > HTTP://cmd.wma.ibm.com:80/ > GET > 200 > > > > I am interested in: >httpRequest > HTTP://cmd.wma.ibm.com:80/ > GET > 200 > as well as the upper layer tag. How do I ge

Re: ElementTree write creates large one line XML file ....

2010-05-28 Thread robert somerville
Thanks Robert Kern : "prettyprint" ; indent() does the trick ;-) >ElementTree writes exactly what you tell it to. In XML, whitespace is >significant. If you want newlines and/or indentation to make it pretty-looking, >then you need to add those to your elements. > >Fredrik provides an example f

Re: ElementTree write creates large one line XML file ....

2010-05-27 Thread Sebastian Bassi
On Thu, May 27, 2010 at 9:13 PM, Robert Kern wrote: > ElementTree writes exactly what you tell it to. In XML, whitespace is > significant. If you want newlines and/or indentation to make it > pretty-looking, then you need to add those to your elements. This is not always true. Let me quote an XML

Re: ElementTree write creates large one line XML file ....

2010-05-27 Thread Robert Kern
On 5/27/10 7:52 PM, robert somerville wrote: Hi I am using Ubuntu 9.10 and Python 2.6.4 .. when I create an ElementTree object and the write it out using: xml.etree.ElementTree.write() , I get one single long single line files, instead of something that looks reasonable , what gives ??? (and

Re: Elementtree install problem in Ubuntu (a newbie ..)

2010-03-10 Thread Philip Semanchuk
On Mar 10, 2010, at 6:48 PM, robert somerville wrote: Hi ; I installed the elementtree and celementree packages throught the synaptic package manager, all seems to go fine through the install ... when i startup python and try to import them (as per the EFFBOTT.org suggestions) .. PROBLEMS .

Re: elementtree XML() unicode

2009-11-05 Thread John Machin
On Nov 5, 12:35 am, Stefan Behnel wrote: > John Machin, 04.11.2009 02:56: > > > On Nov 4, 12:14 pm, Kee Nethery wrote: > >> The reason I am confused is that getResponse2 is classified as an   > >> "str" in the Komodo IDE. I want to make sure I don't lose the non- > >> ASCII characters coming from

Re: elementtree XML() unicode

2009-11-04 Thread Stefan Behnel
John Machin, 04.11.2009 02:56: > On Nov 4, 12:14 pm, Kee Nethery wrote: >> The reason I am confused is that getResponse2 is classified as an >> "str" in the Komodo IDE. I want to make sure I don't lose the non- >> ASCII characters coming from the URL. > > str is all about 8-bit bytes. True in P

Re: elementtree XML() unicode

2009-11-03 Thread Kee Nethery
On Nov 3, 2009, at 7:06 PM, Gabriel Genellina wrote: En Tue, 03 Nov 2009 23:06:58 -0300, Kee Nethery escribió: If there was a place in the official docs for me to append these nuggets of information to the sections for "xml.etree.ElementTree.XML(text)" and "xml.etree.ElementTree.dump(

Re: elementtree XML() unicode

2009-11-03 Thread Gabriel Genellina
En Tue, 03 Nov 2009 23:06:58 -0300, Kee Nethery escribió: If there was a place in the official docs for me to append these nuggets of information to the sections for "xml.etree.ElementTree.XML(text)" and "xml.etree.ElementTree.dump(elem)" I would absolutely do so. http://bugs.python.org/ a

Re: elementtree XML() unicode

2009-11-03 Thread John Machin
On Nov 4, 1:06 pm, Kee Nethery wrote: > On Nov 3, 2009, at 5:27 PM, John Machin wrote: > > > > > On Nov 4, 11:01 am, Kee Nethery wrote: > >> Why is this not working and what do I need to do to use Elementtree > >> with unicode? > > > What you need to do is NOT feed it unicode. You feed it a str

Re: elementtree XML() unicode

2009-11-03 Thread John Machin
On Nov 4, 11:01 am, Kee Nethery wrote: > Having an issue with elementtree XML() in python 2.6.4. > > This code works fine: > >       from xml.etree import ElementTree as et >       getResponse = u'''   > bobblehead city>city''' >       theResponseXml = et.XML(getResponse) > > This code errors out

Re: elementtree XML() unicode

2009-11-03 Thread Gabriel Genellina
En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery escribió: Having an issue with elementtree XML() in python 2.6.4. This code works fine: from xml.etree import ElementTree as et getResponse = u''' bobbleheadcity>city''' theResponseXml = et.XML(getResponse) This code errors

Re: elementtree XML() unicode

2009-11-03 Thread Kee Nethery
On Nov 3, 2009, at 4:44 PM, Gabriel Genellina wrote: En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery escribió: I've removed all the stuff in my code and tried to distill it down to just what is failing. Hopefully I have not removed something essential. Sounds like I did remove somethi

Re: elementtree XML() unicode

2009-11-03 Thread Kee Nethery
On Nov 3, 2009, at 5:27 PM, John Machin wrote: On Nov 4, 11:01 am, Kee Nethery wrote: Having an issue with elementtree XML() in python 2.6.4. This code works fine: from xml.etree import ElementTree as et getResponse = u''' bobbleheadcity''' theResponseXml = et.XML(getRespo

Re: elementtree XML() unicode

2009-11-03 Thread John Machin
On Nov 4, 12:14 pm, Kee Nethery wrote: > On Nov 3, 2009, at 4:44 PM, Gabriel Genellina wrote: > > > En Tue, 03 Nov 2009 21:01:46 -0300, Kee Nethery   > > escribió: > > >> I've removed all the stuff in my code and tried to distill it down   > >> to just what is failing. Hopefully I have not remove

Re: elementtree examples

2009-10-19 Thread Gabriel Genellina
En Mon, 19 Oct 2009 17:02:44 -0300, Robert Kern escribió: On 2009-10-19 14:50 PM, Kee Nethery wrote: Am looking for that level of documentation for each function, interface and object listed in the official docs for elementtree. Does it exist? No. Well, not so detailed, but the selftest.

Re: elementtree examples

2009-10-19 Thread Kee Nethery
On Oct 19, 2009, at 1:02 PM, Robert Kern wrote: On 2009-10-19 14:50 PM, Kee Nethery wrote: Am looking for that level of documentation for each function, interface and object listed in the official docs for elementtree. Does it exist? No. Thank you. Kee -- http://mail.python.org/mailma

Re: elementtree examples

2009-10-19 Thread Robert Kern
On 2009-10-19 14:50 PM, Kee Nethery wrote: Am looking for that level of documentation for each function, interface and object listed in the official docs for elementtree. Does it exist? No. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is

Re: elementtree examples

2009-10-19 Thread Kee Nethery
On Oct 19, 2009, at 12:06 PM, Paul Rubin wrote: Kee Nethery writes: do not appear to contain examples for each object, interface or function. Where would I find examples that use each elementtree function, interface and object? effbot.org has a few. yes I agree it has a few. It's not anyw

Re: elementtree examples

2009-10-19 Thread Paul Rubin
Kee Nethery writes: > do not appear to contain examples for each object, interface or > function. Where would I find examples that use each elementtree > function, interface and object? effbot.org has a few. -- http://mail.python.org/mailman/listinfo/python-list

Re: elementtree

2009-08-25 Thread Nadia Johnson
On Aug 24, 7:29 pm, Dave Angel wrote: > Stefan Behnel wrote: > > Hi, > > > elsa wrote: > > >> I know how to turn HTML into an ElementTree object > > > I don't. ;) > > > ElementTree doesn't have an HTML parser, so what do you use for parsing? > > >> but I don't know > >> how to then view the struct

Re: elementtree

2009-08-24 Thread Carl Banks
On Aug 24, 12:13 am, Stefan Behnel wrote: > Hi, > > elsa wrote: > > I know how to turn HTML into an ElementTree object > > I don't. ;) > > ElementTree doesn't have an HTML parser, so what do you use for parsing? The OP could be feeding the HTML through tidy, or it could be XHTML. > > but I don'

Re: elementtree

2009-08-24 Thread Stefan Behnel
Dave Angel wrote: > Stefan Behnel wrote: >> elsa wrote: >>> I know how to turn HTML into an ElementTree object >> >> I don't. ;) >> >> ElementTree doesn't have an HTML parser, so what do you use for parsing? >> > Perhaps the OP was referring to XHTML, which should be eligible for > ElementTree.

Re: elementtree

2009-08-24 Thread Dave Angel
Stefan Behnel wrote: Hi, elsa wrote: I know how to turn HTML into an ElementTree object I don't. ;) ElementTree doesn't have an HTML parser, so what do you use for parsing? but I don't know how to then view the structure of this object. Is there a method or module that you can

Re: elementtree

2009-08-24 Thread Stefan Behnel
Hi, elsa wrote: > I know how to turn HTML into an ElementTree object I don't. ;) ElementTree doesn't have an HTML parser, so what do you use for parsing? > but I don't know > how to then view the structure of this object. Is there a method or > module that you can give an ElementTree object to

Re: ElementTree - Howto access text within XML tag element...

2009-08-12 Thread Stefan Behnel
cmalmqui wrote: > tree = etree.parse('10_07_2009 16_48_00_history.tcx') > root = tree.getroot() > > elem = root[0][0] > > # iterate over all laps > for i in range(1, len(elem)-1): Note that you can iterate over elements as in for lap_element in elem: # ... Then use

Re: ElementTree - Howto access text within XML tag element...

2009-08-11 Thread Diez B. Roggisch
cmalmqui schrieb: On Aug 11, 9:51 am, "Diez B. Roggisch" wrote: cmalmqui schrieb: Hi, I am writing on a small XML parser and are currently stuck as I am not able to get the whole element name in ElementTree. Please see the below example where "print root[0][0]" returns "" Is there a way to get

Re: ElementTree - Howto access text within XML tag element...

2009-08-11 Thread cmalmqui
On Aug 11, 9:13 am, Ned Deily wrote: > In article > <1ad8dac1-8fff-493a-a197-d847e7b6a...@c2g2000yqi.googlegroups.com>, > >  cmalmqui wrote: > > I am writing on a small XML parser and are currently stuck as I am not > > able to get the whole element name in ElementTree. > > > Please see the below

Re: ElementTree - Howto access text within XML tag element...

2009-08-11 Thread cmalmqui
On Aug 11, 9:51 am, "Diez B. Roggisch" wrote: > cmalmqui schrieb: > > Hi, > > > I am writing on a small XML parser and are currently stuck as I am not > > able to get the whole element name in ElementTree. > > > Please see the below example where "print root[0][0]" returns > > "" > > > Is there a

Re: ElementTree - Howto access text within XML tag element...

2009-08-11 Thread Diez B. Roggisch
cmalmqui schrieb: Hi, I am writing on a small XML parser and are currently stuck as I am not able to get the whole element name in ElementTree. Please see the below example where "print root[0][0]" returns "" Is there a way to get hold of the "Running" string in the tag using elementTree?

Re: ElementTree - Howto access text within XML tag element...

2009-08-11 Thread Ned Deily
In article <1ad8dac1-8fff-493a-a197-d847e7b6a...@c2g2000yqi.googlegroups.com>, cmalmqui wrote: > I am writing on a small XML parser and are currently stuck as I am not > able to get the whole element name in ElementTree. > > Please see the below example where "print root[0][0]" returns > "" >

Re: ElementTree: How to return only unicode?

2009-03-15 Thread Torsten Bronger
Hallöchen! Stefan Behnel writes: > Torsten Bronger wrote: > >> Stefan Behnel writes: >> >>> Torsten Bronger wrote: >>> [...] My problem is that if there is only ASCII, these methods return ordinary strings instead of unicode. So sometimes I get str, sometimes I get unic

Re: ElementTree: How to return only unicode?

2009-03-15 Thread Stefan Behnel
Torsten Bronger wrote: > Hallöchen! und zurück! > Stefan Behnel writes: > >> Torsten Bronger wrote: >> >>> [...] >>> >>> My problem is that if there is only ASCII, these methods return >>> ordinary strings instead of unicode. So sometimes I get str, >>> sometimes I get unicode. Can one change

Re: ElementTree: How to return only unicode?

2009-03-14 Thread Torsten Bronger
Hallöchen! Stefan Behnel writes: > Torsten Bronger wrote: > >> [...] >> >> My problem is that if there is only ASCII, these methods return >> ordinary strings instead of unicode. So sometimes I get str, >> sometimes I get unicode. Can one change this globally so that >> they only return unicod

Re: ElementTree: How to return only unicode?

2009-03-14 Thread Stefan Behnel
Torsten Bronger wrote: > I parse an XML file with ElementTree and get the contets with > the .attrib, .text, .get etc methods of the tree's nodes. > Additionally, I use the "find" and "findtext" methods. > > My problem is that if there is only ASCII, these methods return > ordinary strings instead

Re: ElementTree and clone element toot

2009-02-08 Thread Stefan Behnel
Aahz wrote: > In article <4986bfd7$0$9385$ba4ac...@news.orange.fr>, > m.banaouas wrote: >> Working with the ElementTree module, I looked for clone element >> function but not found such tool: > > Have you tried using copy.deepcopy()? While being the most obvious solution, calling deepcopy() on a

Re: ElementTree and clone element toot

2009-02-08 Thread Aahz
In article <4986bfd7$0$9385$ba4ac...@news.orange.fr>, m.banaouas wrote: > >Working with the ElementTree module, I looked for clone element >function but not found such tool: Have you tried using copy.deepcopy()? -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ We

Re: ElementTree and clone element toot

2009-02-02 Thread Gabriel Genellina
En Mon, 02 Feb 2009 14:21:29 -0200, m.banaouas escribió: My python version is 2.4.4 def SubElement(parent, tag, attrib={}, **extra): Can you tell me how does "parent" issue could be solved by SubElement ? Simply because you *have* to pass a parent to the function... I'm looking for how t

Re: ElementTree and clone element toot

2009-02-02 Thread m.banaouas
My python version is 2.4.4 def SubElement(parent, tag, attrib={}, **extra): Can you tell me how does "parent" issue could be solved by SubElement ? I'm looking for how to determine element parent just by asking element it self. It seems like element doesn't know witch is its parent, while any par

Re: ElementTree and clone element toot

2009-02-02 Thread Gerard Flanagan
Gabriel Genellina wrote: En Mon, 02 Feb 2009 12:37:36 -0200, Gerard Flanagan escribió: e = ET.fromstring(s) def clone(elem): ret = elem.makeelement(elem.tag, elem.attrib) ret.text = elem.text for child in elem: ret.append(clone(child)) return ret f = clone(e)

Re: ElementTree and clone element toot

2009-02-02 Thread Gabriel Genellina
En Mon, 02 Feb 2009 12:37:36 -0200, Gerard Flanagan escribió: e = ET.fromstring(s) def clone(elem): ret = elem.makeelement(elem.tag, elem.attrib) ret.text = elem.text for child in elem: ret.append(clone(child)) return ret f = clone(e) You forget the tail attri

Re: ElementTree and clone element toot

2009-02-02 Thread Gerard Flanagan
m.banaouas wrote: Hi all, Working with the ElementTree module, I looked for clone element function but not found such tool: def CloneElment(fromElem, destRoot = None) fromElem is the element to clone destRoot is the parent element of the new element ; if None so the new element will be child of

Re: ElementTree XML Namspace

2008-11-15 Thread Stefan Behnel
Hunter wrote: > We are reviewing a vendor who will output some data in an XML format. > I will then use python to convert the data to another format for > upload to another vendor. Take a look at lxml.objectify, it has a nicer API, especially if you are new to XML. It also handles loads of namespa

Re: ElementTree XML Namspace

2008-11-14 Thread Mark Tolonen
"Hunter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] We are reviewing a vendor who will output some data in an XML format. I will then use python to convert the data to another format for upload to another vendor. I'm having trouble with very basic steps with the sample file th

Re: ElementTree oddities

2008-09-16 Thread Stefan Behnel
Mark Thomas wrote: > here's how you would do it in lxml (http://codespeak.net/ > lxml/index.html), a library which supports XPath: > > from lxml import etree > tree = etree.fromstring('Bar:') > print ' '.join(tree.xpath('//text()')) If you want to use XPath, try this: print tree.xpath('s

Re: elementtree and rounding questions

2008-07-30 Thread jyoung79
Thank you very much Gabriel and Stefan for your help! I really appreciate the excellent examples you've shared which is helping me understand how all this works. Again, thank you for taking the time to help me with this. Jay -- http://mail.python.org/mailman/listinfo/python-list

Re: elementtree and rounding questions

2008-07-29 Thread Stefan Behnel
[EMAIL PROTECTED] wrote: > > > > > > > > > > > >name="Courier">text > >

Re: elementtree and rounding questions

2008-07-29 Thread Gabriel Genellina
En Wed, 30 Jul 2008 00:56:55 -0300, <[EMAIL PROTECTED]> escribi�: One other question I had was about rounding floats. I was first looking at this syntax to round out to 6 decimal places if needed: f = '508.5' x = '%.6f' % (float(f)/72) x '7.062500' However, in this instance I don't want t

Re: ElementTree and DTDs

2008-05-16 Thread Stefan Behnel
J. Pablo Fernández wrote: > Is ElementTree supposed to load DTDs? AFAIR, you have to provide entities by hand. > Or is there another library that would handle DTDs correctly, > performing entity replacements? http://codespeak.net/lxml http://codespeak.net/lxml/parsing.html#parser-options Stefa

Re: ElementTree and DTDs

2008-05-16 Thread J . Pablo Fernández
Or is there another library that would handle DTDs correctly, performing entity replacements? Thanks. On May 16, 12:20 am, J. Pablo Fernández <[EMAIL PROTECTED]> wrote: > Hello, > > Is ElementTree supposed to load DTDs? I have some xmls heavy on > entities and it fails this way: > > Python 2.5.2

Re: Elementtree find problem

2008-04-21 Thread Stefan Behnel
Mike Slinn wrote: > The following short Python program parses a KML file and displays the > names of all Marks and Routes: > > from elementtree.ElementTree import ElementTree > tree = ElementTree(file='test.kml') > kml = tree.getroot() > ns = 'http://earth.google.com/kml/2.1' > for folder in kml.f

Re: ElementTree and namespaces in the header only

2008-01-16 Thread Peter Bengtsson
On Jan 15, 5:22 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Peter Bengtsson wrote: > > root = Element('feed', xmlns='http://www.w3.org/2005/Atom') > > root.set('xmlns:se', NS_URL) > > entry = SubElement(root, 'entry') > > SubElement(root, 'title').text = 'Title' > > SubElement(entry, SEN('catego

Re: ElementTree and namespaces in the header only

2008-01-15 Thread Torsten Bronger
Hallöchen! Fredrik Lundh writes: > Peter Bengtsson wrote: > >> root = Element('feed', xmlns='http://www.w3.org/2005/Atom') >> root.set('xmlns:se', NS_URL) >> entry = SubElement(root, 'entry') >> SubElement(root, 'title').text = 'Title' >> SubElement(entry, SEN('category')).text = 'Category' > >>

Re: ElementTree and namespaces in the header only

2008-01-15 Thread Fredrik Lundh
Peter Bengtsson wrote: > root = Element('feed', xmlns='http://www.w3.org/2005/Atom') > root.set('xmlns:se', NS_URL) > entry = SubElement(root, 'entry') > SubElement(root, 'title').text = 'Title' > SubElement(entry, SEN('category')).text = 'Category' > But surely the xmlns:se attribute on the tag

Re: Elementtree 1.3 and xpath

2008-01-10 Thread Fredrik Lundh
Andrew Lonie wrote: > Hi I noticed that the xpath functionality of elementtree has been > upgraded in version 1.3. However I can't seem to get the [postion] > predicate to function. All the other new functionality seems to be > working. ET 1.3 is only available in an early alpha yet, and the post

Re: ElementTree should parse string and file in the same way

2008-01-03 Thread Fredrik Lundh
Stefan Behnel wrote: >> also, putting large documents in a *single* Python string can be quite >> inefficient. it's often more efficient to use lists of string fragments. > > That's a pretty general statement. Do you mean in terms of reading from that > string (which at least in lxml is a straig

Re: ElementTree should parse string and file in the same way

2008-01-03 Thread Stefan Behnel
Fredrik Lundh wrote: > Stefan Behnel wrote: > >>> My take on the API decision in question was always that a file is >>> inherently an XML *document*, while a string is inherently an XML >>> *fragment*. >> >> Not inherently, no. I know some people who do web processing with an XML >> document comin

Re: ElementTree should parse string and file in the same way

2008-01-03 Thread Fredrik Lundh
Stefan Behnel wrote: >> My take on the API decision in question was always that a file is >> inherently an XML *document*, while a string is inherently an XML >> *fragment*. > > Not inherently, no. I know some people who do web processing with an XML > document coming in as a string (from an HTTP

Re: ElementTree should parse string and file in the same way

2008-01-03 Thread Stefan Behnel
Hi, Chris Mellon wrote: > On that note, I really don't like APIs that take either a file name or > a file object - I can open my own files, thanks. ... and HTTP URLs, and FTP URLs. In lxml, there is a performance difference between passing an open file (which is read in Python space using the rea

Re: ElementTree should parse string and file in the same way

2008-01-02 Thread Chris Mellon
On Jan 2, 2008 8:56 AM, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Steven D'Aprano wrote: > > > Fredrik, if you're reading this, I'm curious what your reason is. I don't > > have an opinion on whether you should or shouldn't treat files and > > strings the same way. Over to you... > > as Diez shows

Re: ElementTree should parse string and file in the same way

2008-01-02 Thread Fredrik Lundh
Steven D'Aprano wrote: > Fredrik, if you're reading this, I'm curious what your reason is. I don't > have an opinion on whether you should or shouldn't treat files and > strings the same way. Over to you... as Diez shows, it's all about use cases. and as anyone who's used my libraries or read

Re: ElementTree should parse string and file in the same way

2008-01-01 Thread Peter Pei
To answer something posted deep down... It is fine with me if there are two functions - one to parse a file or file handler and one to parse a string, yet the returned objects should be consistent. -- http://mail.python.org/mailman/listinfo/python-list

Re: ElementTree should parse string and file in the same way

2008-01-01 Thread Steven D'Aprano
On Tue, 01 Jan 2008 12:59:44 -0700, Steven Bethard wrote: > Steven D'Aprano wrote: >> On Tue, 01 Jan 2008 13:36:57 +0100, Diez B. Roggisch wrote: >> >>> And codemonkeys know that in python >>> >>> doc = et.parse(StringIO(string)) >>> >>> is just one import away >> >> Yes, but to play devil's adv

Re: ElementTree should parse string and file in the same way

2008-01-01 Thread Steven Bethard
Steven D'Aprano wrote: > On Tue, 01 Jan 2008 13:36:57 +0100, Diez B. Roggisch wrote: > >> And codemonkeys know that in python >> >> doc = et.parse(StringIO(string)) >> >> is just one import away > > Yes, but to play devil's advocate for a moment, > > doc = et.parse(string_or_file) > > would be

Re: ElementTree should parse string and file in the same way

2008-01-01 Thread Steven D'Aprano
On Tue, 01 Jan 2008 13:36:57 +0100, Diez B. Roggisch wrote: > And codemonkeys know that in python > > doc = et.parse(StringIO(string)) > > is just one import away Yes, but to play devil's advocate for a moment, doc = et.parse(string_or_file) would be even simpler. Is there any reason why it

Re: ElementTree should parse string and file in the same way

2008-01-01 Thread Diez B. Roggisch
Steven D'Aprano schrieb: > On Tue, 01 Jan 2008 01:53:47 +, Peter Pei wrote: > >> You are talking shit. It is never about whether it is hard to write a >> wrapper. It is about bad design. I should be able to parse a string and >> a file in exactly same way, and that should be provided as part o

Re: ElementTree should parse string and file in the same way

2008-01-01 Thread Stefan Behnel
Peter Pei wrote: > To be preise [...] Preise the lord, not me. :) Happy New Year! Stefan -- http://mail.python.org/mailman/listinfo/python-list

Re: ElementTree should parse string and file in the same way

2007-12-31 Thread Steven D'Aprano
On Tue, 01 Jan 2008 01:53:47 +, Peter Pei wrote: > You are talking shit. It is never about whether it is hard to write a > wrapper. It is about bad design. I should be able to parse a string and > a file in exactly same way, and that should be provided as part of the > package. Oh my, somebod

Re: ElementTree should parse string and file in the same way

2007-12-31 Thread Peter Pei
To be preise, XPath is not fully supported. Don't be a smart asshole. = "Stefan Behnel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Peter Pei wrote: >> One bad design about elementtree is that it has different wa

Re: ElementTree should parse string and file in the same way

2007-12-31 Thread Peter Pei
You are talking shit. It is never about whether it is hard to write a wrapper. It is about bad design. I should be able to parse a string and a file in exactly same way, and that should be provided as part of the package. Looks like you are just a code monkey not a designer, so I forgive you. Y

Re: ElementTree should parse string and file in teh same way

2007-12-31 Thread James Matthews
When dealing with files you pass it an object! So make your string an object and then it should work! On Dec 31, 2007 8:17 AM, Paddy <[EMAIL PROTECTED]> wrote: > On Dec 31, 3:42 am, "Peter Pei" <[EMAIL PROTECTED]> wrote: > > One bad design about elementtree is that it has different ways parsing a

Re: ElementTree should parse string and file in the same way

2007-12-31 Thread Stefan Behnel
Peter Pei wrote: > One bad design about elementtree is that it has different ways parsing a > string and a file, even worse they return different objects: > 1) When you parse a file, you can simply call parse, which returns a > elementtree, on which you can then apply xpath; ElementTree doesn't su

Re: ElementTree should parse string and file in teh same way

2007-12-30 Thread Paddy
On Dec 31, 3:42 am, "Peter Pei" <[EMAIL PROTECTED]> wrote: > One bad design about elementtree is that it has different ways parsing a > string and a file, even worse they return different objects: > 1) When you parse a file, you can simply call parse, which returns a > elementtree, on which you can

Re: Elementtree tag

2007-12-13 Thread Sean DiZazzo
On Dec 13, 8:46 pm, Waldemar Osuch <[EMAIL PROTECTED]> wrote: > On Dec 13, 7:52 pm, Sean DiZazzo <[EMAIL PROTECTED]> wrote:> I have a another > question... > > > using elementtree, is there a proper way to get at the data > > '123456789' in this tag? > > > '' > > > I tried making it an element, bu

Re: Elementtree tag

2007-12-13 Thread Waldemar Osuch
On Dec 13, 7:52 pm, Sean DiZazzo <[EMAIL PROTECTED]> wrote: > I have a another question... > > using elementtree, is there a proper way to get at the data > '123456789' in this tag? > > '' > > I tried making it an element, but the only attribute that returns > anything is the "tag" attribute. Does

Re: Elementtree find problem

2007-12-11 Thread Larry Bates
[EMAIL PROTECTED] wrote: > I tried the tips I found in other posts but I still get 'none' back: > > import easygui as eg > import xml.etree.ElementTree as ET > import sys > > #kml source is: > # > #http://earth.google.com/kml/2.2";> > # > #Simple placemark > #Attached to the ground. Int

Re: elementtree w/utf8

2007-10-29 Thread Tim Arnold
"Stefan Behnel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Tim Arnold wrote: >> On a related note, I have another question--where/how can I get the >> cElementTree.py module? Sorry for something so basic, but I tried >> installing >> cElementTree, but while I could compile wit

Re: elementtree w/utf8

2007-10-28 Thread Stefan Behnel
Tim Arnold wrote: > On a related note, I have another question--where/how can I get the > cElementTree.py module? Sorry for something so basic, but I tried installing > cElementTree, but while I could compile with setup.py build, I didn't end up > with a cElementTree.py file anywhere. That's be

Re: elementtree w/utf8

2007-10-27 Thread rzzzwilson
Tim Arnold wrote: > On a related note, I have another question--where/how can I get the > cElementTree.py module? Sorry for something so basic, but I tried installing > cElementTree, but while I could compile with setup.py build, I didn't end up > with a cElementTree.py file anywhere. The directo

Re: elementtree w/utf8

2007-10-26 Thread Tim Arnold
"Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Thu, 25 Oct 2007 17:15:36 -0400, Tim Arnold wrote: > >> Hi, I'm getting the by-now-familiar error: >> return codecs.charmap_decode(input,errors,decoding_map) >> UnicodeEncodeError: 'ascii' codec can't enco

  1   2   3   >