change a value to NULL?

B

Bell, Kevin

I'm pulling a list of numbers from MS Excel, but occasionally if there
is no data from excel, the value is an asterisk, but I need to make it
null.

What is the best way to do that? Thus far, I'm using:


for value in myRange:
try:
intV = int(value)
print intV
except:
print "its an asterisk"


but I need to get at my list and substitute the *'s with nulls to load
into a database.

Thanks.

Kevin Bell
 
B

Brett Hoerner

I'm not sure what you mean, really, do you need an official Python
"Null" value? Try None?

In [6]: myCells = ['Mary', 'Bob', None, 'Joe']

In [7]: for cell in myCells:
...: if cell:
...: print cell
...: else:
...: print "NULL VALUE"
...:
Mary
Bob
NULL VALUE
Joe

--

As far as having a Null value to put into the DB, most (SQL) DB's I've
used have a specific SQL command like "INSERT INTO ROW VALUE NULL()",
kind of like the SQL DATE(), etc. I'm really rusty on my syntax etc
right now btw so don't copy and paste that. :p
 
S

Steve Holden

Brett said:
I'm not sure what you mean, really, do you need an official Python
"Null" value? Try None?

In [6]: myCells = ['Mary', 'Bob', None, 'Joe']

In [7]: for cell in myCells:
...: if cell:
...: print cell
...: else:
...: print "NULL VALUE"
...:
Mary
Bob
NULL VALUE
Joe

--

As far as having a Null value to put into the DB, most (SQL) DB's I've
used have a specific SQL command like "INSERT INTO ROW VALUE NULL()",
kind of like the SQL DATE(), etc. I'm really rusty on my syntax etc
right now btw so don't copy and paste that. :p
And besides that, Excel is a spreadsheet not a database :)

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,323
Members
48,008
Latest member
KieraMcGuf

Latest Threads

Top