在我的 Java 中,我有一个中央引导加载程序,它将所有默认值保持为公共静态或私有静态,稍后当需要时,我可以转到其他类/线程并访问它们以进行修改等。例如:
public class main extends JWindow implements MouseListener, MouseMotionListener {
private static boolean isDetect = true;
public static String vncMode = "1980";
...
public main() {
vncMode = C.readIni("vncmode"); // 1980
}
}
public class TCPHandler implements Runnable {
import main.*;
public void run() {
if (main.vncMode.equals("1999" ) ||
main.vncMode.equals("2013")) {
echo(main.vncMode, RED);
} else {
echo(main.vncMode, GREEN);
}
}
}
与 Java 类似,在 Python 中,我如何设置公共静态/私有静态声明,以便我可以从该值的任何其他类访问?
python1.py:
from bgcolors import bgcolors
class Python1(object):
isDetect = True
def run(self):
# expecting vncMode = 1980
print bgcolors.RED + "we are now in 1999: from version: " + vncMode
python2.py:
from bgcolors import bgcolors
class Python2(object):
isDetect = True
def run(self):
# expecting vncMode = 1980
print bgcolors.RED + "we are now in 2013: from version: " + vncMode
主要.py:
from bgcolors import bgcolors
from python1 import Python1
from python2 import Python2
vncMode = "1980"
a = Python1()
a.run()
b = Python2()
b.run()
我如何设置值 1980 并在所有类中获得 1980 ?