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 module bound to the name ‘foo’. A module is not callable. > Here is Singleton.py: You should name the file ‘singleton.py’ instead; modules should be named in all lower-case, as PEP 8 recommends. > Here is myClass.py: Which should be named ‘my_class.py’, instead, by the same rationale. Neither of those is necessary, but it will help dispel the confusion you're experiencing, and help your code be more easily comprehensible to other Python programmers. > #!/usr/bin/env python > import os, sys, string, time, re, subprocess > import Singleton So, you should (after the renames suggested) do either:: import singleton @singleton.Singleton class my_class: or:: from singleton import Singleton @Singleton class my_class: Notice how naming the module in lower-case makes it more easily distinguishable from the class name. More generally, remember that Python is not Java <URL:http://dirtsimple.org/2004/12/python-is-not-java.html>, and you should be grouping your classes into logically coherent files, not one-file-per-class. -- \ “Reality must take precedence over public relations, for nature | `\ cannot be fooled.” —Richard P. Feynman, _Rogers' Commission | _o__) Report into the Challenger Crash_, 1986-06 | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list