如果问题如此愚蠢,请裸露,但我基本上来自 c/c++ 背景。
我有以下代码。
#!/usr/bin/python
import os
class Logger(object):
def __init__ (self):
print "Constructor of Logger "
def logMsg(self):
print "logMsg::"
class FileLogger (Logger):
def __init__ (self):
print "Constructor of File Logger"
def logMsg (self):
print "FileLogger::"
class FTPLogger (Logger):
def __init__ (self):
print "Constructor of FTP Logger"
def logMsg (self):
print "FTPLogger::"
def logMsg(log):
print "Logging Message"
logHandler.logMsg() # **HERE: HOW POSSIBLE TO ACCESS logHandler Variable?**
logHandler = FileLogger ();
logMsg(logHandler);
问题:
FileLogger 类的 logMsg() 函数如何访问 logHandler?
我可以认为'logHandler'是一个全局变量吗?