I'm using this decorator to implement singleton class in python:
http://stackoverflow.com/posts/7346105/revisions
The strategy described above works if and only if the Singleton is
declared and defined in the same file. If it is defined in a different
file and I import that file, it doesn't
MYCLASS.PY:
#!/usr/bin/env python
import os, sys, string, time, re, subprocess
import Singleton
@Singleton
class myClass:
def __init__(self):
print 'Constructing myClass'
def __del__(self):
print 'Destructing myClass'
SINGLETON.PY:
#!/usr/bin/env python
import os,
BTW Here is the traceback:
import myClass
Traceback (most recent call last):
File stdin, line 1, in module
File myClass.py, line 6, in module
@Singleton
TypeError: 'module' object is not callable
Here is Singleton.py:
class Singleton:
def __init__(self, decorated):
On Thu, Dec 22, 2011 at 1:11 PM, Saqib Ali saqib.ali...@gmail.com wrote:
MYCLASS.PY:
#!/usr/bin/env python
import os, sys, string, time, re, subprocess
import Singleton
This imports the module Singleton, not the class or function.
There are two options to deal with this:
from Singleton
You have the same code for both files...
--
http://mail.python.org/mailman/listinfo/python-list
Saqib Ali wrote:
MYCLASS.PY:
#!/usr/bin/env python
import os, sys, string, time, re, subprocess
import Singleton
This should be 'from Singleton import Singleton'
@Singleton
class myClass:
def __init__(self):
print 'Constructing myClass'
At this point, the *instance* of
Thanks for pointing out the mistake!
Works.
- Saqib
On Thu, Dec 22, 2011 at 4:31 PM, Ethan Furman et...@stoneleaf.us wrote:
Saqib Ali wrote:
MYCLASS.PY:
#!/usr/bin/env python
import os, sys, string, time, re, subprocess
import Singleton
This should be 'from Singleton import
Saqib Ali wrote:
I'm using this decorator to implement singleton class in python:
http://stackoverflow.com/posts/7346105/revisions
The strategy described above works if and only if the Singleton is
declared and defined in the same file. If it is defined in a different
file and I import that
Saqib Ali saqib.ali...@gmail.com wrote:
I'm using this decorator to implement singleton class in python:
http://stackoverflow.com/posts/7346105/revisions
The strategy described above works if and only if the Singleton is
declared and defined in the same file. If it is defined in a
Saqib Ali saqib.ali...@gmail.com writes:
BTW Here is the traceback:
import myClass
Traceback (most recent call last):
File stdin, line 1, in module
File myClass.py, line 6, in module
@Singleton
TypeError: 'module' object is not callable
Yes. When you ‘import foo’, you have a
10 matches
Mail list logo