473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

better csv modules and where have object-craft gone?

Hi

I have been using object crafts csv module for quite a few projects,
mainly because I found the csv in python in it's current incarnation
is funtionally inferior to object crafts. The object craft module
for instance allowed you build up csv gradually (ie field at a time
rather the python csv module where the writer does the work a record at
a time) which isn't always the way I would like to work,
also I have always had encoding problems (specifcally it doesn't
support unicode as per the docs) everytime I used the python
module where as the object craft one always worked out of the box.

Only problem is object craft seemed to have disappeared off the face
of the net (ie I can't even resolve their name in DNS).

Which is a pity as I don't have a current copy for 2.3 (windows)
of their csv module.

Does anyone have a copy of the object-craft csv module, or does
anyone know where they have relocated ?

It is a pity if they have disappeared.

Rgds

Tim
Jul 18 '05 #1
3 1567
Oops ignore my comment on the DNS front for object craft,
seems my ISP's DNS just wasn't resolving it earlier today
seems to have popped back up on the radar now though

T

Tim Hoffman wrote:
Hi

I have been using object crafts csv module for quite a few projects,
mainly because I found the csv in python in it's current incarnation
is funtionally inferior to object crafts. The object craft module
for instance allowed you build up csv gradually (ie field at a time
rather the python csv module where the writer does the work a record at
a time) which isn't always the way I would like to work,
also I have always had encoding problems (specifcally it doesn't
support unicode as per the docs) everytime I used the python
module where as the object craft one always worked out of the box.

Only problem is object craft seemed to have disappeared off the face
of the net (ie I can't even resolve their name in DNS).

Which is a pity as I don't have a current copy for 2.3 (windows)
of their csv module.

Does anyone have a copy of the object-craft csv module, or does
anyone know where they have relocated ?

It is a pity if they have disappeared.

Rgds

Tim

Jul 18 '05 #2

Tim> I have been using object crafts csv module for quite a few
Tim> projects, mainly because I found the csv in python in it's current
Tim> incarnation is funtionally inferior to object crafts. The object
Tim> craft module for instance allowed you build up csv gradually (ie
Tim> field at a time rather the python csv module where the writer does
Tim> the work a record at a time) which isn't always the way I would
Tim> like to work, also I have always had encoding problems (specifcally
Tim> it doesn't support unicode as per the docs) everytime I used the
Tim> python module where as the object craft one always worked out of
Tim> the box.

I guess beauty is in the eye of the beholder. The Object Craft folks were
key authors of what's in the Python distribution. If you want to write a
field at a time, you should be able to subclass the csv.writer class and add
writefield() and commit() methods. The first appends to an internal list.
The second calls writerow() and clears the list. Something like this
(untested) code might work:

class FieldWriter(csv.writer):
def __init__(self, *args, **kwds):
csv.writer.__init__(self, *args, **kwds)
self.temp = []

def writefield(self, val):
self.temp.append(val)

def commit(self):
self.writerow(self.temp)
self.temp = []

(Be careful. You'll lose partial results if you don't clean up in a __del__
method.)

As for lack of Unicode support that's a known issue. I suppose it hasn't
been high enough on anyone's list of itches to have attracted any scratching
yet. Still, you might be able to get most of the way there with a subclass:

class UnicodeWriter(csv.writer):
def __init__(self, *args, **kwds):
self.encoding = kwds.get('encoding', 'utf-8')
if 'encoding' in kwds: del kwds['encoding']
csv.writer.__init__(self, *args, **kwds)

def writerow(self, row):
for (i,f) in enumerate(row):
if isinstance(f, unicode):
row[i] = f.encode(self.encoding)

I'm almost certain that reading data in multibyte encodings won't work
though, as the low-level reader is byte-oriented instead of
character-oriented. Patches are welcome to resolve that deficiency.

Skip

Jul 18 '05 #3
Skip Montanaro wrote:
Tim> I have been using object crafts csv module for quite a few
Tim> projects, mainly because I found the csv in python in it's current
Tim> incarnation is funtionally inferior to object crafts. The object
Tim> craft module for instance allowed you build up csv gradually (ie
Tim> field at a time rather the python csv module where the writer does
Tim> the work a record at a time) which isn't always the way I would
Tim> like to work, also I have always had encoding problems (specifcally
Tim> it doesn't support unicode as per the docs) everytime I used the
Tim> python module where as the object craft one always worked out of
Tim> the box. As for lack of Unicode support that's a known issue. I suppose it hasn't
been high enough on anyone's list of itches to have attracted any scratching
yet. Still, you might be able to get most of the way there with a subclass:

class UnicodeWriter(csv.writer):
def __init__(self, *args, **kwds):
self.encoding = kwds.get('encoding', 'utf-8')
if 'encoding' in kwds: del kwds['encoding']
csv.writer.__init__(self, *args, **kwds)

def writerow(self, row):
for (i,f) in enumerate(row):
if isinstance(f, unicode):
row[i] = f.encode(self.encoding)

I'm almost certain that reading data in multibyte encodings won't work
though, as the low-level reader is byte-oriented instead of
character-oriented. Patches are welcome to resolve that deficiency.


Aha! so this is why my csv2po converter is getting strange encodings out...
What I'd really like to write/have is a pure Python implementation of
the csv module. Presumably this would
1) Make Unicode trivial
2) Be slower
Anyhow it would be nice...

David
Jul 18 '05 #4

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

Similar topics

1
by: George Adams | last post by:
I like the idea of compiling DSO modules for Apache. It allows me to turn on or off things we may or may not need at a given time (like mod_ssl, mod_auth_mysql, mod_auth_ldap, etc.) and also...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
1
by: KN | last post by:
Hello, I'm new to this list, and I have an important question at the beginning. There is a matter that concerns me - it's the globales implementation. I've read nearly everything I found about...
47
by: Will Stuyvesant | last post by:
Hello all, So Zope still lives, yay. Well, I like that they use Python. <rant> What amazed me is they write that they "added types to the variables and hope that it will be added to the...
8
by: Rob Snyder | last post by:
Greetings - I have a situation where I need to be able to have a Python function that will take all the modules in a given directory and find all the classes defined in these modules by name....
4
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data...
9
by: Emmanuel Charruau | last post by:
Hi, I am looking for a class or any information which would allow me to make communicate mini-module in c++. I have been looking on the net for some examples of such implementation, but I did...
4
by: Steven T. Hatton | last post by:
You can scroll down to the last line of this post in order to find the question I really want to discuss. I was just pondering the competing applicability of C vs. C++ in certain problem...
6
by: Steven W. Orr | last post by:
Given the following code: (I hope it's as simple as possible) :-) #! /usr/bin/python import new class BASE: def __init__( self ): print 'Hello from BASE init' def m1( self ): print 'M1 Base:...
1
by: stef mientki | last post by:
hello, I've a program where users can make modules, by just dumping them in a certain directory, then they will dynamically link into the program if needed. One of the communication channels...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.