由买买提看人间百态

topics

全部话题 - 话题: instance2
(共0页)
S*******s
发帖数: 13043
1
来自主题: Programming版 - python: how to import a decorator?
I got an error if I want to run test.py:
@singleton
NameError: name 'singleton' is not defined
if I combine the two files, it would be fine.
what is right way to import decorator?
#in module Singleton.py
def singleton(theClass):
""" decorator for a class to make a singleton out of it """
classInstances = {}
def getInstance(*args, **kwargs):
""" creating or just return the one and only class instance.
The singleton depends on the parameters used in __init__ """... 阅读全帖
(共0页)