<?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 Loop Array and Set Variables in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loop-array-and-set-variables/m-p/1263342#M67896</link>
    <description>&lt;P&gt;I probably am going about this completely wrong.. but stuck... I HOPE this is going to make sense ... my mind is spinning...&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to set a few variables at the top of the script.&amp;nbsp; This script is used over and over again with minor tweaks by someone that does not understand python that well (including me)&lt;/P&gt;&lt;P&gt;The purpose is for someone to modify the script and add or Remove Feature Classes that will be read later in the script for COPY etc.&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;As you can see below I have LayerA_DEV and Layer B_DEV in a DEV DB.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I am defining their new location in a TEST DB with LayerA_Tst and LayerBTst&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Users can add a Layer C or Layer D if they choose....&lt;/P&gt;&lt;P&gt;They would then have to create a NEW layersToCopy variables like the two variables layersToCopy1 and layersToCopy2 which points to the To and FROM&lt;/P&gt;&lt;P&gt;I then packaged those into 1 array that I read later.&lt;/P&gt;&lt;P&gt;I am trying to read the MAIN array which gives me 2 elements per read....&lt;/P&gt;&lt;P&gt;As the amount of Layers being read (LayerA_DEV, LayerB_DEV, LayerC_DEV) can increase or decrease I dont know how may variables I would need and dont want to the users to have to comb through the script to add them layer....&amp;nbsp;&lt;/P&gt;&lt;P&gt;If they wanted to add a layer for processing they would only have to add:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;LayerC_DEV&amp;nbsp;= "Database Connections\\xxx.sde\\GIS_DATA.aaa_NEWFC"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;LayerC_Tst = "Database Connections\\yyy.sde\\GIS_DATA.aaa_NEWFC"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;layersToCopy3 =&amp;nbsp;[LayerC_DEV, LayerC_Tst]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;layersToCopy = [layersToCopy1,layersToCopy2, &lt;FONT color="#FF0000"&gt;layersToCopy3&lt;/FONT&gt; ]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the code below would read this and there would be no need by the user to modify anything else...&lt;/P&gt;&lt;P&gt;How can I cycle through the layersToCopy Variable and create the required variables to populate&amp;nbsp; to below&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I can get those written I could cycle through the layersToCopy Array and set the parameters for the Copy_Management&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt; #  THIS IS WHAT I AM TRYING TO DO IN THE FOR LOOP

for layers in layersToCopy:
    # Read the First Value in layersToCopy [LayerA_DEV, LayerA_Tst]z
    # Break apart into 2 varaibles run copy
    arcpy.Copy_management(LayerA_DEV, LayerA_Tst)

    # Read the Second Value in layersToCopy [LayerB_DEV, LayerB_Tst]
    # Break apart into 2 varaibles run copy
    # arcpy.Copy_management(LayerB_DEV, LayerB_Tst)

    # Resulting in 2 new Feature Classes copied to a new DB&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;LayerA_DEV = "Database Connections\\xxx.sde\\GIS_DATA.aaa_LOGSHEET"
LayerB_DEV = "Database Connections\\xxx.sde\\GIS_DATA.aaa_PERMIT_I"

LayerA_Tst = "Database Connections\\yyy.sde\\GIS_DATA.aaa_LOGSHEET"
LayerB_Tst = "Database Connections\\yyy.sde\\GIS_DATA.aaa_PERMIT_I"

layersToCopy1 = [LayerA_DEV, LayerA_Tst]
layersToCopy2 = [LayerB_DEV, LayerB_Tst]
layersToCopy = [layersToCopy1,layersToCopy2]

# I want to loop thorugh layersToCopy and create 4 variables that I can use to Copy Features
for layers in layersToCopy:
    for copyLayers in layers:
        print(copyLayers)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RESULT:&lt;/P&gt;&lt;P&gt;Database Connections\xxx.sde\GIS_DATA.aaa_LOGSHEET&lt;BR /&gt;Database Connections\xxx.sde\GIS_DATA.aaa_LOGSHEET&lt;BR /&gt;Database Connections\yyy.sde\GIS_DATA.aaa_PERMIT_I&lt;BR /&gt;Database Connections\yyy.sde\GIS_DATA.aaa_PERMIT_I&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2023 23:43:09 GMT</pubDate>
    <dc:creator>kapalczynski</dc:creator>
    <dc:date>2023-03-01T23:43:09Z</dc:date>
    <item>
      <title>Loop Array and Set Variables</title>
      <link>https://community.esri.com/t5/python-questions/loop-array-and-set-variables/m-p/1263342#M67896</link>
      <description>&lt;P&gt;I probably am going about this completely wrong.. but stuck... I HOPE this is going to make sense ... my mind is spinning...&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to set a few variables at the top of the script.&amp;nbsp; This script is used over and over again with minor tweaks by someone that does not understand python that well (including me)&lt;/P&gt;&lt;P&gt;The purpose is for someone to modify the script and add or Remove Feature Classes that will be read later in the script for COPY etc.&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;As you can see below I have LayerA_DEV and Layer B_DEV in a DEV DB.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;I am defining their new location in a TEST DB with LayerA_Tst and LayerBTst&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Users can add a Layer C or Layer D if they choose....&lt;/P&gt;&lt;P&gt;They would then have to create a NEW layersToCopy variables like the two variables layersToCopy1 and layersToCopy2 which points to the To and FROM&lt;/P&gt;&lt;P&gt;I then packaged those into 1 array that I read later.&lt;/P&gt;&lt;P&gt;I am trying to read the MAIN array which gives me 2 elements per read....&lt;/P&gt;&lt;P&gt;As the amount of Layers being read (LayerA_DEV, LayerB_DEV, LayerC_DEV) can increase or decrease I dont know how may variables I would need and dont want to the users to have to comb through the script to add them layer....&amp;nbsp;&lt;/P&gt;&lt;P&gt;If they wanted to add a layer for processing they would only have to add:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;LayerC_DEV&amp;nbsp;= "Database Connections\\xxx.sde\\GIS_DATA.aaa_NEWFC"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;LayerC_Tst = "Database Connections\\yyy.sde\\GIS_DATA.aaa_NEWFC"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;layersToCopy3 =&amp;nbsp;[LayerC_DEV, LayerC_Tst]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;layersToCopy = [layersToCopy1,layersToCopy2, &lt;FONT color="#FF0000"&gt;layersToCopy3&lt;/FONT&gt; ]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the code below would read this and there would be no need by the user to modify anything else...&lt;/P&gt;&lt;P&gt;How can I cycle through the layersToCopy Variable and create the required variables to populate&amp;nbsp; to below&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I can get those written I could cycle through the layersToCopy Array and set the parameters for the Copy_Management&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt; #  THIS IS WHAT I AM TRYING TO DO IN THE FOR LOOP

for layers in layersToCopy:
    # Read the First Value in layersToCopy [LayerA_DEV, LayerA_Tst]z
    # Break apart into 2 varaibles run copy
    arcpy.Copy_management(LayerA_DEV, LayerA_Tst)

    # Read the Second Value in layersToCopy [LayerB_DEV, LayerB_Tst]
    # Break apart into 2 varaibles run copy
    # arcpy.Copy_management(LayerB_DEV, LayerB_Tst)

    # Resulting in 2 new Feature Classes copied to a new DB&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;LayerA_DEV = "Database Connections\\xxx.sde\\GIS_DATA.aaa_LOGSHEET"
LayerB_DEV = "Database Connections\\xxx.sde\\GIS_DATA.aaa_PERMIT_I"

LayerA_Tst = "Database Connections\\yyy.sde\\GIS_DATA.aaa_LOGSHEET"
LayerB_Tst = "Database Connections\\yyy.sde\\GIS_DATA.aaa_PERMIT_I"

layersToCopy1 = [LayerA_DEV, LayerA_Tst]
layersToCopy2 = [LayerB_DEV, LayerB_Tst]
layersToCopy = [layersToCopy1,layersToCopy2]

# I want to loop thorugh layersToCopy and create 4 variables that I can use to Copy Features
for layers in layersToCopy:
    for copyLayers in layers:
        print(copyLayers)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RESULT:&lt;/P&gt;&lt;P&gt;Database Connections\xxx.sde\GIS_DATA.aaa_LOGSHEET&lt;BR /&gt;Database Connections\xxx.sde\GIS_DATA.aaa_LOGSHEET&lt;BR /&gt;Database Connections\yyy.sde\GIS_DATA.aaa_PERMIT_I&lt;BR /&gt;Database Connections\yyy.sde\GIS_DATA.aaa_PERMIT_I&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 23:43:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-array-and-set-variables/m-p/1263342#M67896</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2023-03-01T23:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Array and Set Variables</title>
      <link>https://community.esri.com/t5/python-questions/loop-array-and-set-variables/m-p/1263349#M67897</link>
      <description>&lt;P&gt;Think I got it.....&lt;/P&gt;&lt;P&gt;The one thing I can count on is there will only be a From and To so I could use something like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;one,two = layers &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think this is how its split?&lt;/P&gt;&lt;P&gt;Any thoughts?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# Local variables:
LayerA_DEV = "Database Connections\\xxx.sde\\GIS_DATA.aaa_LOGSHEET"
LayerB_DEV = "Database Connections\\yyy.sde\\GIS_DATA.aaa_PERMIT_I"
LayerC_DEV = "Database Connections\\zzz.sde\\GIS_DATA.aaa_PERMIT_C"

LayerA_Tst = "Database Connections\\xxx.sde\\GIS_DATA.aaa_LOGSHEET"
LayerB_Tst = "Database Connections\\yyy.sde\\GIS_DATA.aaa_PERMIT_I"
LayerC_Tst = "Database Connections\\zzz.sde\\GIS_DATA.aaa_PERMIT_C"

layersToCopy1 = [LayerA_DEV, LayerA_Tst]
layersToCopy2 = [LayerB_DEV, LayerB_Tst]
layersToCopy3 = [LayerC_DEV, LayerC_Tst]

layersToCopy = [layersToCopy1,layersToCopy2,layersToCopy3]

def copyFeatures():
    for layers in layersToCopy:
        one, two = layers
        print("Variables as assigned are : ")
        fromFC = (str(one))
        toFC = (str(two))
        print("Going from" + fromFC)
        print("Going to" + toFC)
        #arcpy.Copy_management(fromFC, toFC)

if __name__ == '__main__':
    copyFeatures()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 00:04:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-array-and-set-variables/m-p/1263349#M67897</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2023-03-02T00:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Array and Set Variables</title>
      <link>https://community.esri.com/t5/python-questions/loop-array-and-set-variables/m-p/1263536#M67898</link>
      <description>&lt;P&gt;A possible alternative is to use a Python dictionary. Then you only need to update the dictionary and it could be of any size without having to add/remove additional variables.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Note the format of the dictionary. You pair your source and destination separated by a colon. Then add a comma and repeat for each source/destination pair. The whole thing is wrapped in curly brackets.

layers_to_copy = {
"Database Connections\\xxx.sde\\GIS_DATA.aaa_LOGSHEET": "Database Connections\\yyy.sde\\GIS_DATA.aaa_LOGSHEET",
"Database Connections\\xxx.sde\\GIS_DATA.aaa_PERMIT_I": "Database Connections\\yyy.sde\\GIS_DATA.aaa_PERMIT_I"
}
			
# You could put this portion in a function as you did.
for layer in layers_to_copy.keys():
   fromFC = layer
   toFC = layers_to_copy[layer]
   print(f'Going from {fromFC}')
   print(f'Going to {toFC}')
   arcpy.Copy_management(fromFC, toFC)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 15:08:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-array-and-set-variables/m-p/1263536#M67898</guid>
      <dc:creator>DanielMiranda2</dc:creator>
      <dc:date>2023-03-02T15:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: Loop Array and Set Variables</title>
      <link>https://community.esri.com/t5/python-questions/loop-array-and-set-variables/m-p/1263603#M67899</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/614407"&gt;@DanielMiranda2&lt;/a&gt;&amp;nbsp; &amp;nbsp;Thanks so much... yea this is what I had envisioned ... much more simple.... I am going to mark this as the solution ... Cheers.. and thank you&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 17:11:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-array-and-set-variables/m-p/1263603#M67899</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2023-03-02T17:11:59Z</dc:date>
    </item>
  </channel>
</rss>

