擅长:python、mysql、java
<p>你提到这是在<code>class classMain</code>。虽然这不是解决问题的最佳<a href="http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29" rel="nofollow noreferrer">encapsulation</a>,但您可以通过将变量<code>newFile</code>写回成员变量来共享它,如下所示:</p>
<pre><code>class classMain:
newFile = None
# ... the rest of your code here.
</code></pre>
<p>然后可以通过在类方法中将成员变量作为<code>self.newFile</code>写入并从中读取来引用它。但是,作为<a href="https://stackoverflow.com/a/9753856/517815">Kaustubh mentioned</a>,还有其他方法可以解决这个问题。<a href="http://docs.python.org/tutorial/classes.html" rel="nofollow noreferrer">This documentation</a>也可以帮助你。你知道吗</p>
<p>欢迎来到StackOverflow!祝你好运。你知道吗</p>