我正在使用以下代码在python中实例化单例:
class Singleton(type):
def __init__(cls, name, bases, dic):
super(Singleton, cls).__init__(name, bases, dic)
cls.instance = None
def __call__(cls, *args, **kwargs):
if cls.instance is None:
if DEBUG:
print("Creating NEW Orchestrator instance")
else:
if DEBUG:
print("Using EXISTING Orchestrator instance")
cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
return cls.instance
Run Code Online (Sandbox Code Playgroud)
该初始化如下所示:
def __init__(self, arg=None):
...
Run Code Online (Sandbox Code Playgroud)
当我实例化对象时,它似乎不接受该参数:
Obj = Object("parameter")
Run Code Online (Sandbox Code Playgroud)
arg不等于"parameter"。没有。
我认为这是将* args传递给调用的目的。在首次实例化单例时如何传递参数?
上一个问题"IPython Notebook会话中的多个目录和/或子目录"询问了目录遍历.给出的答案是该功能即将推出.我还看到了一个命令行标志,它在特定目录中启动服务器.我再也找不到这篇文章了.官方文档中未提及该标志.
这个命令行标志是什么设置工作目录?
我们什么时候可以在IPython Notebook中看到目录功能?
谢谢.