<?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 Suggestion on setting up python environment for developing toolbox in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/suggestion-on-setting-up-python-environment-for/m-p/1501476#M70989</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I was looking for ways in which i can setup my working environment for developing toolboxes in arcgis pro. Currently i am using vscode and use arcpy.AddMessage method to print out messages after the tool's execution. Not sure whether this is the recommended way or are there any better ways in which this can be done.&lt;/P&gt;&lt;P&gt;On a side note i like to keep arcgis pro open just to check the output inbetween.&lt;/P&gt;&lt;P&gt;If the community already has similar discussion please do point out. I am new to this.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jul 2024 08:53:06 GMT</pubDate>
    <dc:creator>nomit</dc:creator>
    <dc:date>2024-07-04T08:53:06Z</dc:date>
    <item>
      <title>Suggestion on setting up python environment for developing toolbox</title>
      <link>https://community.esri.com/t5/python-questions/suggestion-on-setting-up-python-environment-for/m-p/1501476#M70989</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I was looking for ways in which i can setup my working environment for developing toolboxes in arcgis pro. Currently i am using vscode and use arcpy.AddMessage method to print out messages after the tool's execution. Not sure whether this is the recommended way or are there any better ways in which this can be done.&lt;/P&gt;&lt;P&gt;On a side note i like to keep arcgis pro open just to check the output inbetween.&lt;/P&gt;&lt;P&gt;If the community already has similar discussion please do point out. I am new to this.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2024 08:53:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/suggestion-on-setting-up-python-environment-for/m-p/1501476#M70989</guid>
      <dc:creator>nomit</dc:creator>
      <dc:date>2024-07-04T08:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Suggestion on setting up python environment for developing toolbox</title>
      <link>https://community.esri.com/t5/python-questions/suggestion-on-setting-up-python-environment-for/m-p/1501602#M70995</link>
      <description>&lt;P&gt;I've actually been working on a framework for managing toolboxes (&lt;A href="https://github.com/hwelch-fle/pytframe2" target="_blank" rel="noopener"&gt;called pytframe/pytframe2 for now&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;The module structure is subject to change, but I've currently got "archelp" and "models" files that contain helper functions (one that overrides print with arcpy.AddMessage and still prints to stdout)&lt;/P&gt;&lt;P&gt;The models file contains some wrapper classes for interacting with tables and feature classes a bit more naturally. I've got some example tools in the production and dev toolboxes as well.&lt;/P&gt;&lt;P&gt;I've been using this dynamic reloading system for about 2 years now and it's great. I either have everyone using the toolbox from a single file on a network share repo, or have them clone the repo down to a system folder (C:/repos/arcpy-tools or something so templated projects can always find their local clone, or the toolbox stays referenced when someone else opens their project)&lt;/P&gt;&lt;P&gt;If you want any more detailed explanations or examples don't be afraid to message me, I'll be continually developing and documenting this system when I get the time.&lt;/P&gt;&lt;P&gt;Here's a snippet for overwriting the print function to support the ArcPro message queue:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import builtins

def print(*values: object,
          sep: str = " ",
          end: str = "\n",
          file = None,
          flush: bool = False,
          severity: Literal['INFO', 'WARNING', 'ERROR'] = "INFO"):
    """ Print a message to the ArcGIS Pro message queue and stdout
    set severity to 'WARNING' or 'ERROR' to print to the ArcGIS Pro message queue with the appropriate severity
    """
    # Join the values into a single string
    message = f"{sep.join(map(str, values))}"
    
    # Print the message to stdout
    builtins.print(f"{severity+': ' if severity != 'INFO' else ''}{sep.join(values)}", sep=sep, end=end, file=file, flush=flush)
    
    # Print the message to the ArcGIS Pro message queue with the appropriate severity
    match severity:
        case "WARNING":
            arcpy.AddWarning(f"{message}")
        case "ERROR":
            arcpy.AddError(f"{message}")
        case _:
            arcpy.AddMessage(f"{message}")
    return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And one of the most useful addin methods I use (only 2 lines of code too!):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def as_dict(cursor: SearchCursor | UpdateCursor) -&amp;gt; Generator[dict[str, Any], None, None]:
    """Convert a search cursor or update cursor to an iterable dictionary generator
    This allows for each row operation to be done using fieldnames as keys.
    
    Arguments:
        cursor: search cursor or update cursor.
        
    Yields:
        dictionary of the cursor row.
    
    NOTE: This function will not overwrite the cursor object
    if used in a context manager and iterating through the yielded
    dictionaries will progress the cursor as if you were iterating
    through the cursor object itself.
    
    usage:
    &amp;gt;&amp;gt;&amp;gt; with SearchCursor(...) as cursor:
    &amp;gt;&amp;gt;&amp;gt;     for row in as_dict(cursor):
    &amp;gt;&amp;gt;&amp;gt;         print(row)
    ------------------------------------------------
    &amp;gt;&amp;gt;&amp;gt; with UpdateCursor(...) as cursor:
    &amp;gt;&amp;gt;&amp;gt;     for row in as_dict(cursor):
    &amp;gt;&amp;gt;&amp;gt;        row["field"] = "new value"
    &amp;gt;&amp;gt;&amp;gt;        cursor.updateRow(list(row.values()))
    """
    yield from (dict(zip(cursor.fields, row)) for row in cursor)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jul 2024 23:00:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/suggestion-on-setting-up-python-environment-for/m-p/1501602#M70995</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-07-04T23:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: Suggestion on setting up python environment for developing toolbox</title>
      <link>https://community.esri.com/t5/python-questions/suggestion-on-setting-up-python-environment-for/m-p/1502287#M71005</link>
      <description>&lt;P&gt;Fascinating, i would try to keep an eye out.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 08:13:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/suggestion-on-setting-up-python-environment-for/m-p/1502287#M71005</guid>
      <dc:creator>nomit</dc:creator>
      <dc:date>2024-07-08T08:13:40Z</dc:date>
    </item>
  </channel>
</rss>

