The code given below is setting value of the field as 'None' instead of Null?
import arcpy
fc = 'c:/data/base.gdb/well'
fields = ['Name']
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
row[0] = None
cursor.updateRow(row)
arcmap version 10.2
I need to set these string values to null ?
None is more or less the Python equivalent of NULL in a database. You are writing Python code, not SQL, here.
Unless you are executing SQL through ODBC with something like pyodbc, and emmitting queries like
<FIELD> IS NULL
you generally would only use None in Python code.
If you want to insert empty strings instead of None, you could simply use
row[0]=''
I know i can set this to ''....but need it to set to nul...not None not ''...anyidea how to do it?
If you are working with a File Geodatabase, like you do, then setting NULL means using None in Python, there is no NULL concept for setting values in a File Geodatabase to None / NULL, you should use None instead as in the code example.
Remember: You are writing Python code here, which is not the same as defining SQL statements for use in ODBC.
If you are working with an Enterprise Geodatabase and writing DML SQL statements and sending them through e.g. ODBC, then yes, you can set the values to NULL, in a DML SQL statement.
try indenting updaterow by one level as in the code examples here
UpdateCursor—Data Access module | Documentation
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
row[0] = None
cursor.updateRow(row)
Make sure the field allows NULL. It could be that ArcGIS is converting None to 'None' if NULL is not allowed in the field.