import arcpy

# Get the current workspace
workspace = arcpy.env.workspace

# If the workspace is not set, use the default geodatabase
if workspace is None:
    workspace = arcpy.GetParameterAsText(0)  # If running as a script tool, this gets the default geodatabase
    if workspace == '' or workspace.lower() == 'none':
        workspace = arcpy.env.scratchGDB  # If still not set, use the scratch geodatabase

# Set the workspace to the determined geodatabase
arcpy.env.workspace = workspace

# Get a list of all feature classes and tables in the geodatabase
datasets = arcpy.ListFeatureClasses() + arcpy.ListTables()

# Iterate through each dataset
for dataset in datasets:
    # Iterate through each field in the dataset
    fields = arcpy.ListFields(dataset)
    for field in fields:
        # Check if the field is editable (not OID or geometry)
        if not field.editable:
            continue
        # Update the field values to NULL if empty
        with arcpy.da.UpdateCursor(dataset, field.name) as cursor:
            for row in cursor:
                if row[0] == '' or row[0] == ' ':
                    row[0] = None
                    cursor.updateRow(row)