擅长:python、mysql、java
<p>虽然我无法重现你的错误(这没关系),但你似乎在这里被搞砸了。你知道吗</p>
<p>在您的案例中,绕过循环问题的简单方法如下:</p>
<ul>
<li>在<code>bar.py</code>中,修改<code>increment</code>函数的行为,将<code>int</code>作为输入参数,并在更新后返回。你知道吗</li>
<li>在<code>foo.py</code>中,更新<code>main</code>以将<code>testCounter</code>作为参数发送并捕获其返回值。你知道吗</li>
<li>纠正<code>foo.py</code>中的import语句(取决于您的约定),同时删除<code>bar.py</code>中的循环导入。你知道吗</li>
</ul>
<p>以下是我为解决这个问题所做的最低限度的代码更改。<br/>
注意:从<code>TestDirectory</code>文件夹中运行。你知道吗</p>
<p><strong>foo.py公司</strong></p>
<pre><code>import bar
def main():
testCounter = 0
testCounter = bar.increment(testCounter)
print(testCounter)
main()
</code></pre>
<p><strong>棒.py</strong></p>
<pre><code>def increment(testCounter):
testCounter += 1
return testCounter
</code></pre>