<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Newbie question!! in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/newbie-question/m-p/228471#M17721</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have used this script before in its original form and had a few dramas, but I have since updated it for our toolbox at work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;## Created By: Cpl Barrett, GASC, 16 Geo Sp Sqn
## Date: 02/05/2013
## Purpose: Take and input feature class and split it based on the unique values
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in the supplied case field. If an ID field is used the result will be
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feature classes for each row in the input. The name of the input fc is
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prefixed to the output fc.
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; note this has thrown an error for null values on a field this will be fixed in the next update.


import arcpy, string, os

def whereClause(fname, fc, i, unique):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Returns a formatted where clause for use in an SQL statement.
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; The format of the where clause is determined by the input field type.
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; # get the field type from the supplied fname using it as a wildcard
&amp;nbsp;&amp;nbsp;&amp;nbsp; field = arcpy.ListFields(fc, fname)
&amp;nbsp;&amp;nbsp;&amp;nbsp; datatype = field[0].type
&amp;nbsp;&amp;nbsp;&amp;nbsp; # construct the whereclause based on if the field is of type Date, Sring or a Number field
&amp;nbsp;&amp;nbsp;&amp;nbsp; if datatype == "Date":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = """%(fname)s = date'%(value)s'""" % {"fname":arcpy.AddFieldDelimiters(fc, fname), "value": str(unique&lt;I&gt;)}
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif datatype =="String":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = """%(fname)s = '%(value)s'""" % {"fname":arcpy.AddFieldDelimiters(fc, fname), "value": str(unique&lt;I&gt;)}
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = """%(fname)s = %(value)s""" % {"fname":arcpy.AddFieldDelimiters(fc, fname), "value": str(unique&lt;I&gt;)}
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; return whereclause

## Get the parameters and do the work
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # input feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # attribute field to search
&amp;nbsp;&amp;nbsp;&amp;nbsp; field = arcpy.GetParameterAsText(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # output workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; outworkspace = arcpy.GetParameterAsText(2)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # list to hold the values found in the attribut table
&amp;nbsp;&amp;nbsp;&amp;nbsp; values = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; # search cursor used to return the field values
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.SearchCursor(fc)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # determine the pefix for the output feature classes
&amp;nbsp;&amp;nbsp;&amp;nbsp; prefix = (os.path.basename(fc)).rstrip(".shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print prefix

&amp;nbsp;&amp;nbsp;&amp;nbsp; # get a list of each value in the attribute table
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values.append(row.getValue(field))

&amp;nbsp;&amp;nbsp;&amp;nbsp; # use set() and list() to get a list containing only the unique values
&amp;nbsp;&amp;nbsp;&amp;nbsp; unique = list(set(values))
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##for i in range(0, len(unique)):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp; print unique&lt;I&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add a message that states how many unique values found in x number of rows
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = str(len(unique)) + " value(s) found in " + str(len(values)) + " rows."
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(message)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # loop through each unique value and create a new fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(0,len(unique)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # get the whereclause
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = whereClause(field, fc, i, unique)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # add a message to show what value is being extracted
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Extracting: " + str(unique&lt;I&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(message)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # validate the name of the output feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = arcpy.ValidateTableName((prefix + "_"+ str(unique&lt;I&gt;)))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # make atemp layer to hold the selected values based on the where clause
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = arcpy.MakeFeatureLayer_management(fc, name, whereclause)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outfc = outworkspace + os.sep + name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # create the output feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(layer, outfc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(("Created: " + outfc))
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add a generic error message to let the user know something has broken
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("Something has gone wrong. Please check the field values to ensure that there are no illegal characters.")
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Return Geoprocessing tool specific errors
&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp; for msg in range(0, arcpy.GetMessageCount()):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.GetSeverity(msg) == 2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddReturnMessage(msg)&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This isn't perfect yet as it has an issue when fields contain null values. Haven't had a chance to alter it yet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope it helps&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dave&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 11:07:03 GMT</pubDate>
    <dc:creator>DaveBarrett</dc:creator>
    <dc:date>2021-12-11T11:07:03Z</dc:date>
    <item>
      <title>Newbie question!!</title>
      <link>https://community.esri.com/t5/python-questions/newbie-question/m-p/228467#M17717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi there,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm pretty new to GIS in general, but am starting to look into Python scripts and downloadable toolboxes to see how they work. I've downloaded this python script and toolbox, but can't seem to get it to work properly, so am looking for some advice?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://arcscripts.esri.com/details.asp?dbid=14127"&gt;http://arcscripts.esri.com/details.asp?dbid=14127&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure if it's something straightforward and obvious I'm missing, or if it's something a bit more specific to my files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've added the toolbox to ArcToolbox, and then specify my input shapefile (points based) as feature layer, field to query as FID (though I've tried changing this to see if it makes a difference and it doesn't!) and then an output folder (leaving output filename blank). My error message is as follows: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;Executing (SplitLayerByAttributes_3): SplitLayerByAttributes All_VPs FID # C:\Users\lisa\Desktop\test&lt;BR /&gt;Start Time: Fri Aug 02 11:54:34 2013&lt;BR /&gt;Running script SplitLayerByAttributes...&lt;BR /&gt;Error in script SplitLayerByAttributes.&lt;BR /&gt;Error in executing: cmd.exe /C W:\5USERA~1\Lisa\ArcGIS\Scripts\SPLITL~1\SPLITL~1.PY&amp;nbsp; "All_VPs" "FID" "#" "C:\Users\lisa\Desktop\test"&lt;BR /&gt;&lt;BR /&gt;Failed to execute (SplitLayerByAttributes_3).&lt;BR /&gt;End Time: Fri Aug 02 11:54:35 2013 (Elapsed Time: 1.00 seconds)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any advice much appreciated! I'm running GIS 9.2.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lisa&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Aug 2013 09:56:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/newbie-question/m-p/228467#M17717</guid>
      <dc:creator>LisaMcRavey1</dc:creator>
      <dc:date>2013-08-02T09:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie question!!</title>
      <link>https://community.esri.com/t5/python-questions/newbie-question/m-p/228468#M17718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi there,&lt;BR /&gt;&lt;BR /&gt;I'm pretty new to GIS in general, but am starting to look into Python scripts and downloadable toolboxes to see how they work. I've downloaded this python script and toolbox, but can't seem to get it to work properly, so am looking for some advice?&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://arcscripts.esri.com/details.asp?dbid=14127"&gt;http://arcscripts.esri.com/details.asp?dbid=14127&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I'm not sure if it's something straightforward and obvious I'm missing, or if it's something a bit more specific to my files.&lt;BR /&gt;&lt;BR /&gt;I've added the toolbox to ArcToolbox, and then specify my input shapefile (points based) as feature layer, field to query as FID (though I've tried changing this to see if it makes a difference and it doesn't!) and then an output folder (leaving output filename blank). My error message is as follows: &lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;Executing (SplitLayerByAttributes_3): SplitLayerByAttributes All_VPs FID # C:\Users\lisa\Desktop\test&lt;BR /&gt;Start Time: Fri Aug 02 11:54:34 2013&lt;BR /&gt;Running script SplitLayerByAttributes...&lt;BR /&gt;Error in script SplitLayerByAttributes.&lt;BR /&gt;Error in executing: cmd.exe /C W:\5USERA~1\Lisa\ArcGIS\Scripts\SPLITL~1\SPLITL~1.PY&amp;nbsp; "All_VPs" "FID" "#" "C:\Users\lisa\Desktop\test"&lt;BR /&gt;&lt;BR /&gt;Failed to execute (SplitLayerByAttributes_3).&lt;BR /&gt;End Time: Fri Aug 02 11:54:35 2013 (Elapsed Time: 1.00 seconds)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Any advice much appreciated! I'm running GIS 9.2.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Lisa&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Based on the error it is most likely the path you supplied that used the wrong slash format in a string.&amp;nbsp; The following techniques will all work in a Python script path:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1.) forward slashes = /&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2.) double backslashes = \\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3.) raw string with backslashes = r"H:\InfoRequest"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Single backshashes do not work, since the backshash is an escape character that is not read as a string character when it is by itself in a string that is not interpreted raw.&amp;nbsp; So "C:\Users\lisa\Desktop\test" is invalid in Python.&amp;nbsp; These would be valid:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"C:/Users/lisa/Desktop/test"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"C:\\Users\\lisa\\Desktop\\test"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;r"C:\Users\lisa\Desktop\test"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Aug 2013 10:35:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/newbie-question/m-p/228468#M17718</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-08-02T10:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie question!!</title>
      <link>https://community.esri.com/t5/python-questions/newbie-question/m-p/228469#M17719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not having seen the script or toolbox, I would suggest&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;running the script itself in IDLE or Pythonwin&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(supplying any arguments passed from the toolbox&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;such as input fc, split fiield, etcetera).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That will allow you to see what is going on at the script level&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;instead of at the toolbox level.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rfairhur24's advice is appropriate too.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Aug 2013 10:42:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/newbie-question/m-p/228469#M17719</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-08-02T10:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie question!!</title>
      <link>https://community.esri.com/t5/python-questions/newbie-question/m-p/228470#M17720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I I communicated with you offline, don't use the desktop as the source and/or destination for the inputs and result.&amp;nbsp;&amp;nbsp; 9.2 is no longer supported&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Aug 2013 13:39:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/newbie-question/m-p/228470#M17720</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2013-08-02T13:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie question!!</title>
      <link>https://community.esri.com/t5/python-questions/newbie-question/m-p/228471#M17721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have used this script before in its original form and had a few dramas, but I have since updated it for our toolbox at work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;## Created By: Cpl Barrett, GASC, 16 Geo Sp Sqn
## Date: 02/05/2013
## Purpose: Take and input feature class and split it based on the unique values
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; in the supplied case field. If an ID field is used the result will be
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; feature classes for each row in the input. The name of the input fc is
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prefixed to the output fc.
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; note this has thrown an error for null values on a field this will be fixed in the next update.


import arcpy, string, os

def whereClause(fname, fc, i, unique):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Returns a formatted where clause for use in an SQL statement.
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; The format of the where clause is determined by the input field type.
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; # get the field type from the supplied fname using it as a wildcard
&amp;nbsp;&amp;nbsp;&amp;nbsp; field = arcpy.ListFields(fc, fname)
&amp;nbsp;&amp;nbsp;&amp;nbsp; datatype = field[0].type
&amp;nbsp;&amp;nbsp;&amp;nbsp; # construct the whereclause based on if the field is of type Date, Sring or a Number field
&amp;nbsp;&amp;nbsp;&amp;nbsp; if datatype == "Date":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = """%(fname)s = date'%(value)s'""" % {"fname":arcpy.AddFieldDelimiters(fc, fname), "value": str(unique&lt;I&gt;)}
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif datatype =="String":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = """%(fname)s = '%(value)s'""" % {"fname":arcpy.AddFieldDelimiters(fc, fname), "value": str(unique&lt;I&gt;)}
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = """%(fname)s = %(value)s""" % {"fname":arcpy.AddFieldDelimiters(fc, fname), "value": str(unique&lt;I&gt;)}
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; return whereclause

## Get the parameters and do the work
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # input feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # attribute field to search
&amp;nbsp;&amp;nbsp;&amp;nbsp; field = arcpy.GetParameterAsText(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # output workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; outworkspace = arcpy.GetParameterAsText(2)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # list to hold the values found in the attribut table
&amp;nbsp;&amp;nbsp;&amp;nbsp; values = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; # search cursor used to return the field values
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.SearchCursor(fc)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # determine the pefix for the output feature classes
&amp;nbsp;&amp;nbsp;&amp;nbsp; prefix = (os.path.basename(fc)).rstrip(".shp")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print prefix

&amp;nbsp;&amp;nbsp;&amp;nbsp; # get a list of each value in the attribute table
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values.append(row.getValue(field))

&amp;nbsp;&amp;nbsp;&amp;nbsp; # use set() and list() to get a list containing only the unique values
&amp;nbsp;&amp;nbsp;&amp;nbsp; unique = list(set(values))
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##for i in range(0, len(unique)):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp;&amp;nbsp;&amp;nbsp; print unique&lt;I&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add a message that states how many unique values found in x number of rows
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = str(len(unique)) + " value(s) found in " + str(len(values)) + " rows."
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(message)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # loop through each unique value and create a new fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(0,len(unique)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # get the whereclause
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; whereclause = whereClause(field, fc, i, unique)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # add a message to show what value is being extracted
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Extracting: " + str(unique&lt;I&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(message)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # validate the name of the output feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = arcpy.ValidateTableName((prefix + "_"+ str(unique&lt;I&gt;)))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # make atemp layer to hold the selected values based on the where clause
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = arcpy.MakeFeatureLayer_management(fc, name, whereclause)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outfc = outworkspace + os.sep + name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # create the output feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(layer, outfc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(("Created: " + outfc))
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add a generic error message to let the user know something has broken
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("Something has gone wrong. Please check the field values to ensure that there are no illegal characters.")
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Return Geoprocessing tool specific errors
&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp; for msg in range(0, arcpy.GetMessageCount()):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.GetSeverity(msg) == 2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddReturnMessage(msg)&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This isn't perfect yet as it has an issue when fields contain null values. Haven't had a chance to alter it yet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope it helps&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dave&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:07:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/newbie-question/m-p/228471#M17721</guid>
      <dc:creator>DaveBarrett</dc:creator>
      <dc:date>2021-12-11T11:07:03Z</dc:date>
    </item>
  </channel>
</rss>

