I am attempting to convert Java code to Jython and am using the apache Log and LogFactory imports. I am attempting to emulate Foo.class in Jython The chunk of code is as follows: in Java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MyClass {
private static final Log log = LogFactory.getLog(MyClass.class);
public MyClass(Document dom)
{ //code
}
How can I emulate this same behavior of MyClass.class in Jython/Python?
asked May 31, 2012 at 16:10
Bggreen
1231 gold badge4 silver badges10 bronze badges
-
You do realize you can import java classes in jython right?Jakob Bowyer– Jakob Bowyer2012年05月31日 16:16:59 +00:00Commented May 31, 2012 at 16:16
-
Yes I have the imports, The issue is emulating MyClass.classBggreen– Bggreen2012年05月31日 17:27:49 +00:00Commented May 31, 2012 at 17:27
1 Answer 1
To illustrate my comment:
from org.apache.commons.logging import LogFactory
class MyClass(object):
def __init__(self, dom):
"code"
log = LogFactory.getLog(MyClass)
Or
MyClass.log = LogFactory.getLog(MyClass)
answered May 31, 2012 at 17:42
jfs
417k211 gold badges1k silver badges1.7k bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Tobias Kienzler
I suspect OP didn't grasp that in jython
MyClass corresponds to java's MyClass.class, i.e. there is no .class attribute of a classdefault