csv blank fields

Peter Otten __peter__ at web.de
Sat Jun 27 13:12:44 EDT 2009


Mag Gam wrote:

Please don't top-post.

> Sorry if I wasn't clear before.
> 
> While reading my csv file, notice I am putting the content in an array.

That's already in the code you posted. What's missing is the value of 
"mtypes". I really meant it when I asked you to provide a self-contained 
example, i. e. one that I can run on my computer.
 
> If lets say, row[5] has nothing in it

No, it containes an empty string as MRAB already inferred.

> , python gives an exception.

What exception? What traceback? Please take the time to read
http://catb.org/esr/faqs/smart-questions.html

> Instead of the exception, I would like to assign 'NULL' to row[5].

The string "NULL"? That would be

# untested
for s, row in enumerate(reader):
    row = tuple(c if c else "NULL" for c in row)
    t = np.array([row], dtype=mtype)
    ...

I'm not a numpy expert, but creating a lot of temporary arrays does look 
wasteful...

> Does that help?

Sorry, no. I (or someone else who doesn't bother to guess) could have come 
up with a better answer in a shorter time if you had actually answered my 
questions.

Peter




More information about the Python-list mailing list