473,795 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with cPickle and cElementTree

I recently tried switching from ElementTree to cElementTree. My
application parses a collection of large XML files and creates indexes
based on certain attributes. This entire collection is saved as an
instance of my Database class. Using ElementTree and cPickle has
allowed me to save these instances and use them later.

Using cElementTree significantly reduces parse time (~50%) and memory
~(15%) but cPickle refuses to pickle the database object. I receive:

TypeError: expecting string or Unicode object, NoneType found

The offending line of code simple shows my invocation of cPickle,
which is not helpful.

Doing exactly the same thing with ElementTree works fine.

It appears that the objects returned by cElementTree do not pickle
correctly. Is this a know issue? I was unable to find any reports of
this problem.

Any info would be appreciated!

Barry
Oct 9 '08 #1
1 2170
Barry wrote:
I recently tried switching from ElementTree to cElementTree. My
application parses a collection of large XML files and creates indexes
based on certain attributes. This entire collection is saved as an
instance of my Database class. Using ElementTree and cPickle has
allowed me to save these instances and use them later.

Using cElementTree significantly reduces parse time (~50%) and memory
~(15%) but cPickle refuses to pickle the database object. I receive:

TypeError: expecting string or Unicode object, NoneType found

The offending line of code simple shows my invocation of cPickle,
which is not helpful.

Doing exactly the same thing with ElementTree works fine.

It appears that the objects returned by cElementTree do not pickle
correctly. Is this a know issue? I was unable to find any reports of
this problem.
Pickling is (almost always) built-in for pure Python classes, but it needs to
be implemented explicitly for C classes. cElementTree simply doesn't support this.

If you need a fast and memory friendly XML engine *and* want to pickle
elements, take a look at lxml.objectify. Note that it's only partially
compatible with ElementTree, so you will have to change your code (lxml.etree
is mostly compatible, but it doesn't support pickling). It's a very
easy-to-use XML library, though.

Stefan
Oct 10 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2141
by: sh | last post by:
Hi guys, Well, I have a (maybe dumb) question. I want to write my own little blog using Python (as a fairly small but doable project for myself to learn more deaply Python in a web context). I don't want so far to use a database as a backend, I'd prefer use XML which is enough for a small amount of data the blog would have to deal with.
5
9454
by: Marcus Lowland | last post by:
Hello, I'm fairly new to python and have read about and wanted to begin experimenting with cpickle. As I understand, this should be a native module in the python library. I have python 2.3 and now just installed 2.4, but am not able to import or find cpickle.py in any directory of the install, or in the previous version (pickle.py is present and imports correctly). Is there a seperate module package that must be downloaded and installed......
27
1978
by: Igor V. Rafienko | last post by:
Hi, I am trying to understand how cElementTree's clear works: I have a (relatively) large XML file, that I do not wish to load into memory. So, naturally, I tried something like this: from cElementTree import iterparse for event, elem in iterparse("data.xml"): if elem.tag == "schnappi":
2
1752
by: Mike | last post by:
I know XML is more (processor) costly than cPickle, but how bad is it? The idea is I want to store data that can be described as XML into my database as cPickle objects. Except my web framework has no support for BLOB datatype yet, and I might have to go with XML. Ideas are appreciated, Thanks, Mike
0
2051
by: Manuzhai | last post by:
Hello there, I have this weird problem with a mod_python application. Recently I installed ElementTree and cElementTree through ez_setup.py, even though they were already installed normally (this might not be too smart, but I don't think it's related to my actual problem). I have a web application written on top of mod_python that uses cElementTree for several things. After installing cElementTree through
1
1359
by: Piet van Oostrum | last post by:
I have just installed Python 2.5 on Mac OS X 10.4.8 on an iBook (PPC) from the dmg. Now I tried to install cElementTree -1.0.5-20 from source (no egg available in cheeseshop) and got the following compilation error: gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -DXML_STATIC -DHAVE_MEMMOVE=1 -DXML_NS=1...
2
2215
by: mukappa | last post by:
I found an earlier post about subclassing cElementTree.Element which can't be done because it is a factory method. I am trying to subclass XMLTreeBuilder with success using the python implementation, but not with cElementTree. $ python Python 2.3.4 (#1, Feb 22 2005, 04:09:37) on linux2
2
1654
by: Danny Shevitz | last post by:
Howdy, In my app I need to exec user text that defines a function. I want this function to unpickle an object. Pickle breaks because it is looking for the object definition that isn't in the calling namespace. I have mocked up a simple example that shows the problem. Run this first code (from create_pickle.py) to create the pickle. create_pickle.py: (run this first)
4
7565
by: Daniel | last post by:
Hello, I'm trying to build a very simple IPC system. What I have done is create Data Transfer Objects (DTO) for each item I'd like to send across the wire. I am serializing these using cPickle. I've also tried using pickle (instead of cPickle), but I get the same response. Below is the code. I'll put the rest of my comments after the code
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.