<?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: Why does function with 2 parameters throw &amp;quot;myfunction() takes 1 positional argument but 2 were given&amp;quot; in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726648#M56338</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think ArcGIS itself just caches the entire script, .py or .pyc, the first time it is used in a session.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Its really annoying for me as a developer, but there are work arounds when developing, such as rename your .tbx or .py file, so arcgis makes a new cache for this entirely new file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apart from during development, it really shouldnt be an issue, as if you are making regular changes to part of your code, then that part should probably be a tool parameter!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 19 Jul 2019 12:43:16 GMT</pubDate>
    <dc:creator>LukeWebb</dc:creator>
    <dc:date>2019-07-19T12:43:16Z</dc:date>
    <item>
      <title>Why does function with 2 parameters throw "myfunction() takes 1 positional argument but 2 were given"</title>
      <link>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726643#M56333</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So my project structure is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;project_folder\&lt;BR /&gt;&amp;nbsp; &amp;nbsp; mypackage\&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; __init__.py&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; process.py&lt;BR /&gt;&amp;nbsp; &amp;nbsp; main.py&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my &lt;STRONG&gt;__init__.py&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; mypackage&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;process&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;process.py&lt;/STRONG&gt; looks as follows, note without classes !!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy


&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;run_process&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;param1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; param2&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;param1 &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;" "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;param2&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddError&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetMessages&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;in my main.py I do&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; mypackage&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;process &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; process‍&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and then in my code I call run_process() method:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;process&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;run_process&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'test'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'another test'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now this runs perfectly if I start the script from my IDE. I pass two arguments to a function with two parameters &lt;STRONG&gt;BUT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;once I call the script from within ArcGIS Pro -&amp;gt; Toolbox -&amp;gt; Script, I get the following error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;TypeError: run_process() takes 1 positional argument but 2 were given&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone please help me to reproduce this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:04:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726643#M56333</guid>
      <dc:creator>RichardReinicke</dc:creator>
      <dc:date>2021-12-12T07:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why does function with 2 parameters throw "myfunction() takes 1 positional argument but 2 were given"</title>
      <link>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726644#M56334</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried closing and re-opening ArcGIS Pro? I've just seen it ignore changes I've been making to my scripts when using this kind of 'import' setup - specifically ignoring changes to the code I'm importing but seeing changes to the code doing the import. I closed and re-opened Pro and it started working as expected, until I made more changes. Seems like it's caching imported code somehow?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jul 2019 12:29:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726644#M56334</guid>
      <dc:creator>PeteCrosier</dc:creator>
      <dc:date>2019-07-12T12:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why does function with 2 parameters throw "myfunction() takes 1 positional argument but 2 were given"</title>
      <link>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726645#M56335</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/163965"&gt;Richard,&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look at your project structure folder using a file explorer and see if there is a process.pyc file. &amp;nbsp;Delete this file and try to run the script again. &amp;nbsp;Also, there is a python method called Process with a capital “P”, be careful using similar naming in your code. &amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jul 2019 13:20:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726645#M56335</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2019-07-12T13:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why does function with 2 parameters throw "myfunction() takes 1 positional argument but 2 were given"</title>
      <link>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726646#M56336</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Peter, Hello Lance,&lt;BR /&gt;&lt;BR /&gt;thank you both for your helpful comments. It turned out that reopening ArcGIS Pro indeed solved my problem and it may somehow also relate to the __pycache__ subfolders with *.pyc files I have. But because I have the __pycache__ folders in my projects which I would have to delete over and over, I decided that reopening ArcGIS Pro is the more "comfortable" option. &lt;BR /&gt;&lt;BR /&gt;Of course it`s still annoying and it would be interresting if there's a way to circumvent this problem and to make ArcGIS Pro always run the latest local version.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2019 08:02:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726646#M56336</guid>
      <dc:creator>RichardReinicke</dc:creator>
      <dc:date>2019-07-17T08:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why does function with 2 parameters throw "myfunction() takes 1 positional argument but 2 were given"</title>
      <link>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726647#M56337</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/163965" target="_blank"&gt;Richard,&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try adding the following code as the first two lines in your scripts even before your other import statements.&amp;nbsp; This will prevent the pyc files from being generated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; sys
sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;dont_write_bytecode &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will need to delete the pyc files if they have already been created but the script will no longer generate new pyc files. &amp;nbsp;There may still be issues with the modules you are importing, try adding&amp;nbsp;these two lines to these as well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:04:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726647#M56337</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2021-12-12T07:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Why does function with 2 parameters throw "myfunction() takes 1 positional argument but 2 were given"</title>
      <link>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726648#M56338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think ArcGIS itself just caches the entire script, .py or .pyc, the first time it is used in a session.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Its really annoying for me as a developer, but there are work arounds when developing, such as rename your .tbx or .py file, so arcgis makes a new cache for this entirely new file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apart from during development, it really shouldnt be an issue, as if you are making regular changes to part of your code, then that part should probably be a tool parameter!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Jul 2019 12:43:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/why-does-function-with-2-parameters-throw-quot/m-p/726648#M56338</guid>
      <dc:creator>LukeWebb</dc:creator>
      <dc:date>2019-07-19T12:43:16Z</dc:date>
    </item>
  </channel>
</rss>

