<p>它不是首选方法,但是您可以使用<code>global CipherText</code>而不是<code>decmescommand()</code>中的<code>global CT</code>,并且您的变量在所有地方都可以访问。当前变量<code>CT</code>有您的<code>CipherText</code>,它在所有地方都可以访问-因此您可以在<code>encmescommand()</code>内使用<code>CT</code>而不是<code>CipherText</code></p>
<p>有一件事:方法<code>encmescommand()</code>必须在<code>decmescommand()</code>之前执行,以便为<code>CipherText</code>/<code>CT</code>赋值</p>
<hr/>
<p><strong>编辑:</strong></p>
<p>参见示例</p>
<pre><code>class Decmesbuttons():
def decmescommand(self):
print('execute decmescommand()')
print('CipherText:', CipherText)
class Encmesbuttons():
def encmescommand(self):
print('execute encmescommand()')
global CipherText
CipherText = "hello world"
d = Decmesbuttons()
e = Encmesbuttons()
e.encmescommand() # <- you have to run it before decmescommand()
d.decmescommand()
</code></pre>
<p>结果:</p>
<pre><code>execute encmescommand()
execute decmescommand()
CipherText: hello world
</code></pre>
<hr/>
<p><strong>编辑:</strong>更喜欢的方法</p>
<pre><code>class Decmesbuttons():
def decmescommand(self, text):
print('execute decmescommand()')
print('CipherText:', text)
class Encmesbuttons():
def encmescommand(self):
print('execute encmescommand()')
CipherText = "hello world"
return CipherText
d = Decmesbuttons()
e = Encmesbuttons()
result = e.encmescommand() # <- you have to run it before decmescommand()
d.decmescommand(result)
</code></pre>