Skip to content

OpenSource 1000ASA.com

Sections
Personal tools
You are here: Home » Support forum » Stripping white space

Forum Post : Stripping white space

Up one level
Posted by at 2007-01-08 16:35

In the data file I'm importing, some (but not all) of the fields have trailing white space. It's voter data, and the political party field has "D " instead of just "D".

I used to clean the data before I imported it, but now I've patched ArcheCSV to remove the white space itself as it imports. I don't know enough python yet to make this into a checkbox configuration option, but you may find it useful.

Patch the file /skins/startimport.py:

        for f in at_fields:
            try:
                k=at_mapping[f.getName()]
                atdict[f.getName()]=csvdata[i][k]
            except(KeyError):
                pass

Change the assignment line to the following:

                atdict[f.getName()]=csvdata[i][k].strip()

You can use lstrip or rstrip to remove left (leading) or right (trailing) whitespace; strip removes both.

« September 2008 »
Su Mo Tu We Th Fr Sa
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
 
 

Powered by Plone

This site conforms to the following standards: