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.