<?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: How do you write a function that includes code completion like arcpy functions? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-you-write-a-function-that-includes-code/m-p/351192#M27536</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you put the function into a python module "mystuff.py" and import it, then it will be available (with its documentation string, if any) from the python command window. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But why not make yourself a .pyt or .tbx toolbox and import it with arcpy.ImportToolbox? This will show both tool and parameter usage documentation while you're using it and allow you to access picklists for the parameters on the command line.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Dec 2012 16:20:01 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2012-12-12T16:20:01Z</dc:date>
    <item>
      <title>How do you write a function that includes code completion like arcpy functions?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-write-a-function-that-includes-code/m-p/351191#M27535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a few functions for sets of tasks I do routinely. I'd like to have the dropdown of all feature classes in my document pop-up in the python command-line window like when I use a built in arcpy function. Is there a way to set up the parameters to do that? Here's a sample function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def classClip(myInput, myClip, outFeature, outTable): &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_analysis(myInput, myClip, outFeature) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(outFeature, "ClipAcres", "Double", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(outFeature, "ClipAcres", "float(!SHAPE.AREA@ACRES!)", "PYTHON") &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Statistics_analysis(outFeature, outTable, [["ClipAcres", "SUM"]], "AAClass")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Dec 2012 16:04:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-write-a-function-that-includes-code/m-p/351191#M27535</guid>
      <dc:creator>KennethPierce</dc:creator>
      <dc:date>2012-12-12T16:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write a function that includes code completion like arcpy functions?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-write-a-function-that-includes-code/m-p/351192#M27536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you put the function into a python module "mystuff.py" and import it, then it will be available (with its documentation string, if any) from the python command window. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But why not make yourself a .pyt or .tbx toolbox and import it with arcpy.ImportToolbox? This will show both tool and parameter usage documentation while you're using it and allow you to access picklists for the parameters on the command line.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Dec 2012 16:20:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-write-a-function-that-includes-code/m-p/351192#M27536</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-12-12T16:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do you write a function that includes code completion like arcpy functions?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-you-write-a-function-that-includes-code/m-p/351193#M27537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Making a .tbx is probably the best, but I have used something like this in the past. I have a whole series of these little helper functions in a script. Some functions use arcpy some don't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#to import a custom module from a network
import sys
sys.path.append(r"\\snarf\am\div_lm\ds\gis\tools\scripts_toolboxes")
import helper #script is helper.py that is in the scripts_toolboxes folder&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def searchFiles(rootDir, wildcard = "*"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Returns a list of files under rootDir that contain the wildcard search string"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; fileList = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(rootDir) == False:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "ERROR: " + rootDir + " does not exist!"
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for dirPath, dirNames, fileNames in os.walk(rootDir, topdown=True):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for file in fileNames:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fnmatch.fnmatch(file, wildcard) == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fileList.append(dirPath + "\\" + file)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return fileList&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:30:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-you-write-a-function-that-includes-code/m-p/351193#M27537</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T16:30:40Z</dc:date>
    </item>
  </channel>
</rss>

