| Who | When |
Messages | |
(not accepting new messages)
|
|
| Exemaker won't work
|
85
|
 |
|
10-10-2004 18:19 UTC
|
|
Traceback (most recent call last): File "c:\pl\python23\exemaker.py", line 2, in ? import site ImportError: No module named site
|
Fredrik Lundh
|
84
|
 |
|
09-10-2004 18:13 UTC
|
|
"one unresolved issue is how to have the xml encoding added to the top of the output file"
By default, the element writer omits the XML header and uses ASCII as the encoding (an XML parser will treat this as a UTF-8 document, which is ASCII-compatible). To specify another encoding, pass the encoding keyword argument to the write method:
tree.write("outfile.xml", encoding="iso-8859-1")
Note that the writer uses character references for characters that cannot be represented in the given encoding, so you don't really have to bother with encodings.
|
midtoad
|
83
|
 |
|
09-10-2004 17:59 UTC
|
|
this note is for other beginner users of ElementTree.
Here's how to parse a simple XML file with attributes in it, add an item to the tree, then delete an item. At this point, one unresolved issue is how to have the xml encoding added to the top of the output file.
#et1.py from elementtree import ElementTree import os
'''our input file population2.xml looks like this: <?xml version='1.0' encoding='utf-8'?> <population> <person name="joe" sex="male" age="49"></person> <person name="hilda" sex="female" age="33"></person> <person name="bartholomew" sex="male" age="17"></person> </population> '''
os.chdir("d:\\data\\python\\effbot") tree = ElementTree.parse("population2.xml") root = tree.getroot()
# display entire tree in standard output ElementTree.dump(root)
print ''
# add an element elem = ElementTree.Element("population") newelem = ElementTree.SubElement(elem, "person", name="Fred", sex="male", age="47") root.append(newelem) ElementTree.dump(root) print ''
# delete an element for it in tree.findall("person"): if it.attrib["name"] == "joe": print "I found Joe!" root.remove(it) break else: raise AssertionError("Where's joe?")
ElementTree.dump(root) print ''
tree.write("outfile.xml")
--- cheers Stewart Midwinter
|
Stewart Midwinter
|
82
|
 |
|
07-10-2004 16:52 UTC
|
|
re: ElementTree under Python 1.5.2
Following your advice, I made a slight modification to my code and now have it working under Python 1.5.2. The only catch was that for some reason, Python 1.5.2 could not find the SimpleXMLTreeBuilder module, even though it was installed with ElementTree in the ..\Python\elementtree folder; only after I copied it to my data-file directory did my script work.
code under Python 2.3.4: from elementtree.ElementTree import ElementTree root = ElementTree(file="sample.xml") ...
code under Python 1.5.2: import ElementTree import SimpleXMLTreeBuilder parser = SimpleXMLTreeBuilder.TreeBuilder() tree = ElementTree.parse("sample.xml", parser) root = tree.getroot() ...
|
Fredrik Lundh
|
81
|
 |
|
07-10-2004 06:43 UTC
|
|
Quoting the README:
The modules are designed to work with Python 2.1 and newer. The core ElementTree module and the SimpleXMLTreeBuilder class also works under 1.5.2 and 2.0. /.../
Usage:
import ElementTree, SimpleXMLTreeBuilder parser = SimpleXMLTreeBuilder.TreeBuilder() tree = ElementTree.parse("sample.xml", parser)
Note that xmllib doesn't always handle namespaces properly; see the notes in the README file for details.
Hope this helps!
|
| Stewart Midwinter
|
80
|
 |
|
06-10-2004 21:21 UTC
|
|
ElementTree needs Python >v.2.0?
I downloaded and tested ElementTree and found it a useful way to simplify my parsing of an xml file. Then I tried it with Python 1.5.2 and it complained that it couldn't find module expat in xml.parsers. I take it this means that I need a higher version of Python? Is there still a version of ElementTree that will work with good ol' 1.5.2? (yes, I know all of the benefits of 2.3.4, but my employer is using a customized version of 1.5.2 so I can't upgrade right now.
|
Fredrik Lundh
|
79
|
 |
|
27-09-2004 20:10 UTC
|
|
Edited by author 27-09-2004 20:10
The f(*args) syntax was added in Python 2.0. For older versions, you can use apply(f, args) instead. In this case, you'd have to write:
apply(c.coords, (polygon_item,) + tuple(newxy))
|
| Stewart Midwinter
|
78
|
 |
|
27-09-2004 19:45 UTC
|
|
re: September 20, 2004 Tkinter Tricks: Using Complex Numbers to Rotate Canvas Items
Just read the bit on using complex numbers for Tkinter canvas coordinates: good trick! Code sample wouldn't run for me, choking on the following line: c.coords(polygon_item, *newxy) My default version of Python is 1.52 (my employer still uses this old version for a number of reasons), so I switched to Python 2.3.4 and the code ran fine.
Thanks again for the tip.
|
Fredrik Lundh
|
77
|
 |
|
16-09-2004 10:02 UTC
|
|
Yup. Just wish it hadn't taken me ten minutes to realize what was going on...
$ rm -rf font/.svn
$ svn add font
|
| The Badger
|
76
|
 |
|
16-09-2004 09:52 UTC
|
|
Re: argh
Nice to see that the Subversion people managed to reproduce CVS's quirks, too.
|
| Brian
|
75
|
 |
|
13-09-2004 20:09 UTC
|
|
uname -a Darwin brianl.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug 5 19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC Power Macintosh powerpc
python Python 2.4a3 (#6, Sep 7 2004, 17:36:39) [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
setup.py: FREETYPE_ROOT = ("/sw/lib", "/sw/lib/freetype2/include")
python setup.py build_ext -i running build_ext --- using frameworks at /Library/Frameworks --------------------------------------------------------- PIL 1.1.5a4 BUILD SUMMARY --------------------------------------------------------- version 1.1.5a4 platform darwin 2.4a3 (#6, Sep 7 2004, 17:36:39) [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] --------------------------------------------------------- --- TKINTER support ok --- JPEG support ok --- ZLIB (PNG/ZIP) support ok --- FREETYPE support ok ---------------------------------------------------------
python selftest.py 55 tests passed.
I'm using a framework build of TCL/TK 8.4.7 ls -d /Library/Frameworks/T* /Library/Frameworks/Tcl.framework /Library/Frameworks/Tk.framework
|
| infidel
|
74
|
 |
|
13-09-2004 17:48 UTC
|
|
I'm not at all surprised at the lack of US media attention given to the Russian school tragedy. When the evening news devotes many minutes of airtime to cheesy animations about Jennifer Lopez and Ben Affleck or the latest Brittney Spears "controversy" then one can only assume that some preponderance of viewers actually cares about such garbage. It's hard to see someone who cares enough about Brittney and J.Lo. to want them in the evening news caring about anything in Russia. As if these people could even find Russia on a map.
Covering the weather is easy. Covering real news is harder and riskier.
|
| selasley
|
73
|
 |
|
13-09-2004 14:13 UTC
|
|
Darwin Scotts-Mac.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug 5 19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC Power Macintosh powerpc
[~/Desktop/Imaging-1.1.5a4] sel% python Python 2.3.4 (#1, Jun 12 2004, 13:49:49) [GCC 3.3 20030304 (Apple Computer, Inc. build 1640)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> ^D
[~/Desktop/Imaging-1.1.5a4] sel% python setup.py build_ext -i ... -------------------------------------------------------------------- PIL 1.1.5a4 BUILD SUMMARY -------------------------------------------------------------------- version 1.1.5a4 platform darwin 2.3.4 (#1, Jun 12 2004, 13:49:49) [GCC 3.3 20030304 (Apple Computer, Inc. build 1640)] -------------------------------------------------------------------- *** TKINTER support not available (Tcl/Tk 8.4 libraries needed) --- JPEG support ok --- ZLIB (PNG/ZIP) support ok --- FREETYPE support ok --------------------------------------------------------------------
[~/Desktop/Imaging-1.1.5a4] sel% python selftest.py 55 tests passed.
Notes: libjpeg, etc installed with iInstaller, not fink. OS X python 2.3 was replaced with version 2.3.4, Tcl/Tk Aqua 8.4.7 installed
|
| Phil
|
72
|
 |
|
13-09-2004 11:04 UTC
|
|
OS X 10.2.8 bash-2.05a$ uname -a Darwin TheComputer.local. 6.8 Darwin Kernel Version 6.8: Wed Sep 10 15:20:55 PDT 2003; root:xnu/xnu-344.49.obj~2/RELEASE_PPC Power Macintosh powerpc -------------------------------------------------------------------- PIL 1.1.5a4 BUILD SUMMARY -------------------------------------------------------------------- version 1.1.5a4 platform darwin 2.3 (#2, Jul 30 2003, 11:45:28) [GCC 3.1 20020420 (prerelease)] -------------------------------------------------------------------- *** TKINTER support not available --- JPEG support ok --- ZLIB (PNG/ZIP) support ok --- FREETYPE support ok *** Warning: zlib 1.1.3 may contain a security vulnerability. *** Consider upgrading to zlib 1.1.4 or newer. *** See: http://www.gzip.org/zlib/advisory-2002-03-11.txt-------------------------------------------------------------------- bash-2.05a$ python2.3 selftest.py *** The _imaging C module is not installed * Needed to add library path for fink freetype to `setup.py`. * Found FAQ re: error message on your site, but hit self-imposed time-limit, sorry... :-)
|
| Kevin Cazabon
|
71
|
 |
|
05-09-2004 19:30 UTC
|
|
I guess living in Europe now I get a lot more European news. I'm amazed that with Sept. 11 still in everyone's minds (this week is the anniversary after all) that terrorism like this would take second rate to a hurricane. I personally think it's as significant as Sept. 11, and even sadder due to them TARGETING kids.
Especially with the "potential" link to Al Queda (that doesn't look right...), you'd think they'd be all over that.
Personally, I couldn't care less about Clinton's bypass, the upcoming elections, and whatnot (being a Canadian that's easy to say though), but my heart sank following the Russia tragedy (I spent a little too much time at work trying to keep up with events on it).
One thing that's tough to get though is ANY news about Canada. :)
Kevin.
|
Fredrik Lundh
|
70
|
 |
|
05-09-2004 18:43 UTC
|
|
Kevin, what puzzled me was that none of the US blogs I read has mentioned this, at all. Not even the "political blogs", nor the ones that use to cover international terrorism. And when I checked US media on friday afternoon and yesterday, everyone was busy with Clinton's bypass, and yet another hurricane. As were the bloggers. I don't really know what to make of this, but I do find it a bit disturbing.
|