Hello,
at the moment I'm testing python scripts in ArcGIS Pro, a very basic technique. But because ArcGIS Pro 2.3 works with python 3.6 in my case, I wanted to structure my code a bit more leveraging classes, modules, packages.
So my project structure is as follows:
project_folder\
mypackage\
__init__.py
process.py
main.py
my __init__.py
<SPAN class="keyword token">import</SPAN> mypackage<SPAN class="punctuation token">.</SPAN>process<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
process.py looks as follows, note without classes !!!
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">run_process</SPAN><SPAN class="punctuation token">(</SPAN>param1<SPAN class="punctuation token">,</SPAN> param2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>param1 <SPAN class="operator token">+</SPAN> <SPAN class="string token">" "</SPAN> <SPAN class="operator token">+</SPAN>param2<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddError<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetMessages<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>in my main.py I do
<SPAN class="keyword token">import</SPAN> mypackage<SPAN class="punctuation token">.</SPAN>process <SPAN class="keyword token">as</SPAN> process
and then in my code I call run_process() method:
process<SPAN class="punctuation token">.</SPAN>run_process<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'test'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'another test'</SPAN><SPAN class="punctuation token">)</SPAN>
Now this runs perfectly if I start the script from my IDE. I pass two arguments to a function with two parameters BUT
once I call the script from within ArcGIS Pro -> Toolbox -> Script, I get the following error message:
TypeError: run_process() takes 1 positional argument but 2 were given
I can't get behind this error message and was researching on this problem a lot. Most occurences of such errors are related to method inside instances passing themself as additional first argument automatically but this shouln't be the case here.
Moreover it tells me that my run_process() function would have only 1 parameter what is definetly not the case. The function takes 2 parameters!
Can someone please help me to reproduce this?