Skip to main content

Posts

Showing posts with the label python

XPath Matching in Unique XML Namespaces (xmlns)

I ran into a problem trying to get my Python script to locate an etree node in an XML document that had declared a namespace for all elements in the document. The trouble I was seeing is that the find and xpath functions weren't returning anything for any of the searches I was doing. Nothing seemed to make sense until I realized that I wasn't including the namespace in the search. The bugger with this is that you have to declare the ns on each and every element in the document! To simplify things a little, i went with code that looked a little like this: The full code: from lxml import etree as ET fp = open("sitemap.xml","r") element = ET.parse(fp) namespace = "{http://www.sitemaps.org/schemas/sitemap/0.9"}" e = element.findall('{0}url'.format(namespace)) for i in e: print i.text

Manipulating XML Using Python

I work with XML-related content on a day-to-day basis at work. I come from a .NET background and have written dozens of applications that leverage DOM when manipulating XML. Recently, I've started broadening my horizons to include more languages. I've written a few applications in Python now to do similar tasks as my .NET applications and there's one area that I always find lacking: XML manipulation with eTree. Perhaps I'm mistaken, but it appears from community pages that eTree is the defacto standard in Python for manipulating XML. Sure, it does *most* things correctly, but every once in a while, I can't help but stop and think, this was a whole lot easier with such and such method in .NET or, why does etree.xpath() work when etree.find() doesn't? Why are there two ways to do essentially the same thing in the same class library anyway? One area that eTree really lacks cohesive support is mixed type XML ( Some Text some more text even more text. ). Dealing ...

PyDev and Code Completion

I was struggling with code completion/hinting in PyDev on Eclipse 3.5.2 (default for Ubuntu) and came across this little useful tidbit on the Internet: 'To enable code completion, go to Window > Preferences > Pydev > Editor > Code Completion, and check the 'Use Code Completion?' box, as well as the other boxes for what you want to complete on. It seems to take a second to load, the first time it has to complete something.' Problem solved! I now have my autocomplete settings just the way I want them! Thanks Internet! If I haven't said it lately, you're awesome.

The Ultimate Python IDE: Eclipse + pyDev

I posted awhile ago about my recommendation for an IDE (Wingware's IDE). I'd like to retract that recommendation in favor of one I've been experimenting with lately: Eclipse + pyDev. First off, the IDE is open source and is one of the most popular IDEs on the market today. I wasn't aware of how Aptana had fully integrated Python as a plugin until yesterday. I can only say that I am extremely pleased with the result. They did it right, no doubt about it. Check it out on your favorite OS today. For Ubuntu 10.04 users, simply add Eclipse to your system through the Software Center and then follow the instructions on pydev.org to add it as a plugin. Make sure you follow the instructions for adding it as a plugin.

Unable to Install Eclipse Plugins in Ubuntu 10.04

I wanted to give pyDev a spin after installing a new copy of Ubuntu 10.04 with Eclipse. Turns out it needs one additional package to install Eclipse plugins correctly. I kept getting this error: The artifact file for osgi.bundle,org.eclipse.cvs,1.0.400.v201002111343 was not found. Here's the fix : sudo apt-get install eclipse-pde

I Loves My Python, Loves My Python

The title comes from a cute little cartoon in "Bowling for Columbine" where a redneck is cradling a rifle while purring, "I loves my gun, loves my gun." Python is by far my favorite interpreted language. I use it for all sorts of things: client tools (thank you wxGlade!), server scripting, personal file management, and on and on... If you're serious about using Python, I think you'll really want a project-oriented IDE with debugging, variable inspection, and code hinting. I use Wingware's IDE. Anyone recommend alternatives? Tips for using Wingware IDE?

Deciding on the Best Python GUI Designer: Pt. 2

So, I've developed my first GUI Ubuntu app using Python and wxPython. I ended up doing the layout in wxGlade. Once I figured out how the sizers work, it was cake. I'm still a bit disappointed with some of the cross-platform GUI layout decisions wx makes, but hey, it's not exactly productive trying to emulate a Microsoft "standard", is it? SO, verdict? wxGlade gets the job done. LOVE the way Python handles the class-based UI stuff and wxGlade makes adding more stuff later a snap without worrying about overwriting anything accidentally. Now, on to SOAP integration with Python...

Deciding on the Best Python GUI Designer

I've been learning the various front-end dev tools for RAD Python development lately. I first went to QT because of the extensive design tools available for it. I quickly ruled it out due to its licensing restrictions. I next gave the various wxPython designers/IDEs a look over. I started with wxGlade as it seems to be commonly used on the Internet. After running through some tutorials, I'm fairly satisfied that it could do what I need but it does lack some of the more advanced layout options. Boa Constructor shows promise but is pretty convoluted and lacks a certain "polish" that I'm looking for. I also gave PythonCard a go but it's miserable on Linux, so it's probably out as well... Any recommendations out there for a solid wxPython layout environment? Do I just need to stick with wxGlade and hope for the best?

Getting Help Working in Qt Designer

After install Qt Designer, if you want to use the help system, you're stuck unless you install one more package through Synaptic: Qt Assistant. However, there is no stand-alone for this program. It is bundled in the dev tools. Making it stand-alone is a valid request to the dev team for the Qt suite of packages. At the very least, if Qt Assistant is not made standalone then it should be a dependent of Qt Designer. Otherwise, if Qt Assistant isn't pulled from the qt4-dev-tools package, then Qt Designer should *REQUIRE* qt4-dev-tools as a dependant. Otherwise, users will install Qt Designer and not have any way of figuring out why they don't have help menu options available once installed. As a workaround, users who have installed Qt Designer must then install (through Synaptic Package Manager) "qt4-dev-tools". That also adds a bunch of stuff they don't need, but at least they can then use the help system for Qt Designer. Here's a link to this bug.