From: Jake B <ota...@gm...> - 2007-08-21 04:01:40
|
Hello, I have used Python for some time, but because my current project involves the use of the Java library Batik, I have decided to learn to use Jython. I am not familiar with the Batik API, and so I am really missing the autocomplete (Ctrl + Space) feature that I would normally have when writing Java code in Eclipse. The autocomplete feature displays all of an object's public methods, as well as other publicly accessible constructs, and I believe that this feature provides a very fast, dynamic way of learning an unfamiliar API. I understand that due to Python and Jython's dynamic typing system, autocomplete is generally not possible. However, I was wondering if there were any other function that could retrieve an object's public methods and other constructs. For instance, I believe that in Python I could run inspect.getmembers(circbbox, inspect.ismethod) to get the public methods. However, this does not seem to work in Jython. I would appreciate any guidance anyone can can offer. Thanks. Jake |
From: Oti <oh...@gm...> - 2007-08-21 04:37:57
|
Jake, maybe you try out Don Coleman's Jython Console: http://code.google.com/p/jythonconsole/ best wishes, Oti. On 8/21/07, Jake B <ota...@gm...> wrote: > Hello, I have used Python for some time, but because my current project > involves the use of the Java library Batik, I have decided to learn to use > Jython. I am not familiar with the Batik API, and so I am really missing the > autocomplete (Ctrl + Space) feature that I would normally have when writing > Java code in Eclipse. The autocomplete feature displays all of an object's > public methods, as well as other publicly accessible constructs, and I > believe that this feature provides a very fast, dynamic way of learning an > unfamiliar API. > I understand that due to Python and Jython's dynamic typing system, > autocomplete is generally not possible. However, I was wondering if there > were any other function that could retrieve an object's public methods and > other constructs. For instance, I believe that in Python I could run > inspect.getmembers(circbbox, inspect.ismethod) to get the public methods. > However, this does not seem to work in Jython. > I would appreciate any guidance anyone can can offer. > Thanks. > > Jake > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |
From: Pekka L. <pe...@ik...> - 2007-08-21 15:57:13
|
2007/8/21, Jake B <ota...@gm...>: > I was wondering if there > were any other function that could retrieve an object's public methods and > other constructs. You probably already know about it but simply using dir(object) gives you list of all the object's attributes. If you are only interested about methods, relatively simple code like below can help. >>> from java.lang import String >>> from types import MethodType >>> s = String('') >>> for a in [a for a in dir(s) if type(getattr(s, a)) is MethodType ]: ... print a Cheers, .peke |
From: Jake B <ota...@gm...> - 2007-08-22 23:52:33
|
Thank you for the quick replies! Jythonconsole is very interesting. Also, I found that the commercial version of Pydev supports some autocompletion and autoimports libraries. Unfortunately, Pydev autocompletion doesn't work perfectly, and jythonconsole does not yet adequately fulfill my needs for an editing environment. For now, I'd just be happy to have the inspect module working. The developer of jythonconsole says that he uses inspect.py in his implementation, but whenever i'm using jython and I try to import it, I always get an error message saying that the module cannot be found. When I'm in python, however, I'm able to import it just fine. If anyone has any advice as to how I could troubleshoot this, I would greatly appreciate it if you would let me know. Thanks. Jake On 8/21/07, Pekka Laukkanen <pe...@ik...> wrote: > > 2007/8/21, Jake B <ota...@gm...>: > > I was wondering if there > > were any other function that could retrieve an object's public methods > and > > other constructs. > > You probably already know about it but simply using dir(object) gives > you list of all the object's attributes. If you are only interested > about methods, relatively simple code like below can help. > > >>> from java.lang import String > >>> from types import MethodType > >>> s = String('') > >>> for a in [a for a in dir(s) if type(getattr(s, a)) is MethodType ]: > ... print a > > > Cheers, > .peke > |
From: Jake B <ota...@gm...> - 2007-08-22 23:57:46
|
Just a quick note: I tried import inspect under jython 2.2rc3, and it works fine, but it fails under jython 2.1. Is this normal? Please let me know. Thanks. Jake On 8/22/07, Jake B <ota...@gm...> wrote: > > Thank you for the quick replies! Jythonconsole is very interesting. Also, > I found that the commercial version of Pydev supports some autocompletion > and autoimports libraries. Unfortunately, Pydev autocompletion doesn't work > perfectly, and jythonconsole does not yet adequately fulfill my needs for an > editing environment. > For now, I'd just be happy to have the inspect module working. The > developer of jythonconsole says that he uses inspect.py in his > implementation, but whenever i'm using jython and I try to import it, I > always get an error message saying that the module cannot be found. When I'm > in python, however, I'm able to import it just fine. > If anyone has any advice as to how I could troubleshoot this, I would > greatly appreciate it if you would let me know. Thanks. > > Jake > > On 8/21/07, Pekka Laukkanen <pe...@ik...> wrote: > > > > 2007/8/21, Jake B < ota...@gm...>: > > > I was wondering if there > > > were any other function that could retrieve an object's public methods > > and > > > other constructs. > > > > You probably already know about it but simply using dir(object) gives > > you list of all the object's attributes. If you are only interested > > about methods, relatively simple code like below can help. > > > > >>> from java.lang import String > > >>> from types import MethodType > > >>> s = String('') > > >>> for a in [a for a in dir(s) if type(getattr(s, a)) is MethodType ]: > > ... print a > > > > > > Cheers, > > .peke > > > > |
From: Don C. <dco...@ch...> - 2007-08-23 14:41:45
|
Your import failed because inspect.py is not included with Jython 2.1. For jythonconsole I used inspect.py from CPython 2.2.2. On 8/22/07, Jake B <ota...@gm...> wrote: > Just a quick note: > I tried import inspect under jython 2.2rc3, and it works fine, but it fails > under jython 2.1. > Is this normal? > Please let me know. Thanks. > > Jake > > > On 8/22/07, Jake B <ota...@gm...> wrote: > > Thank you for the quick replies! Jythonconsole is very interesting. Also, > I found that the commercial version of Pydev supports some autocompletion > and autoimports libraries. Unfortunately, Pydev autocompletion doesn't work > perfectly, and jythonconsole does not yet adequately fulfill my needs for an > editing environment. > > For now, I'd just be happy to have the inspect module working. The > developer of jythonconsole says that he uses inspect.py in his > implementation, but whenever i'm using jython and I try to import it, I > always get an error message saying that the module cannot be found. When I'm > in python, however, I'm able to import it just fine. > > If anyone has any advice as to how I could troubleshoot this, I would > greatly appreciate it if you would let me know. Thanks. > > > > Jake > > > > > > > > On 8/21/07, Pekka Laukkanen <pe...@ik...> wrote: > > > 2007/8/21, Jake B < ota...@gm...>: > > > > I was wondering if there > > > > were any other function that could retrieve an object's public methods > and > > > > other constructs. > > > > > > You probably already know about it but simply using dir(object) gives > > > you list of all the object's attributes. If you are only interested > > > about methods, relatively simple code like below can help. > > > > > > >>> from java.lang import String > > > >>> from types import MethodType > > > >>> s = String('') > > > >>> for a in [a for a in dir(s) if type(getattr(s, a)) is MethodType ]: > > > ... print a > > > > > > > > > Cheers, > > > .peke > > > > > > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |
From: Charlie G. <cha...@gm...> - 2007-08-23 16:15:11
|
inspect has been added to Jython 2.2, so you should be able to import it with that version. Charlie On 8/23/07, Don Coleman <dco...@ch...> wrote: > Your import failed because inspect.py is not included with Jython 2.1. > For jythonconsole I used inspect.py from CPython 2.2.2. > > On 8/22/07, Jake B <ota...@gm...> wrote: > > Just a quick note: > > I tried import inspect under jython 2.2rc3, and it works fine, but it fails > > under jython 2.1. > > Is this normal? > > Please let me know. Thanks. > > > > Jake > > > > > > On 8/22/07, Jake B <ota...@gm...> wrote: > > > Thank you for the quick replies! Jythonconsole is very interesting. Also, > > I found that the commercial version of Pydev supports some autocompletion > > and autoimports libraries. Unfortunately, Pydev autocompletion doesn't work > > perfectly, and jythonconsole does not yet adequately fulfill my needs for an > > editing environment. > > > For now, I'd just be happy to have the inspect module working. The > > developer of jythonconsole says that he uses inspect.py in his > > implementation, but whenever i'm using jython and I try to import it, I > > always get an error message saying that the module cannot be found. When I'm > > in python, however, I'm able to import it just fine. > > > If anyone has any advice as to how I could troubleshoot this, I would > > greatly appreciate it if you would let me know. Thanks. > > > > > > Jake > > > > > > > > > > > > On 8/21/07, Pekka Laukkanen <pe...@ik...> wrote: > > > > 2007/8/21, Jake B < ota...@gm...>: > > > > > I was wondering if there > > > > > were any other function that could retrieve an object's public methods > > and > > > > > other constructs. > > > > > > > > You probably already know about it but simply using dir(object) gives > > > > you list of all the object's attributes. If you are only interested > > > > about methods, relatively simple code like below can help. > > > > > > > > >>> from java.lang import String > > > > >>> from types import MethodType > > > > >>> s = String('') > > > > >>> for a in [a for a in dir(s) if type(getattr(s, a)) is MethodType ]: > > > > ... print a > > > > > > > > > > > > Cheers, > > > > .peke > > > > > > > > > > > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by: Splunk Inc. > > Still grepping through log files to find problems? Stop. > > Now Search log events and configuration files using AJAX and a browser. > > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > _______________________________________________ > > Jython-users mailing list > > Jyt...@li... > > https://lists.sourceforge.net/lists/listinfo/jython-users > > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |
From: Jake B <ota...@gm...> - 2007-08-23 16:56:58
|
You are correct, I am able to import inspect with Jython 2.2. It doesn't seem to work on all classes though. For example, I can do this, and everything is happy: Jython Completion Shell JythJython Completion Shell Jython 2.2 on java1.5.0_10 >>> import inspect >>> class Test: ... def testMethod(): ... print 'foo' ... >>> t = Test() >>> t <<unknown>.Test instance 1> >>> inspect.getmembers(t,inspect.ismethod) [('testMethod', <method Test.testMethod of Test instance 1>)] But if I try the same thing with a JFrame, it doesn't work: >>> from javax.swing import JFrame >>> f = JFrame() >>> f javax.swing.JFrame[frame0,0,0,0x0,invalid,hidden,layout= java.awt.BorderLayout ,title=,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane= javax.swing.JRootPane[,0,0,0x0,invalid,layout= javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0 ,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true] >>> inspect.getmembers(f,inspect.ismethod) Traceback (most recent call last): File "<input>", line 1, in ? File "/mathworks/home/jbeard/jythonconsole-0.0.4/inspect.py", line 160, in getmembers value = getattr(object, key) TypeError: write only attribute Is this normal? Could anyone explain why this is happening? Please let me know. Thanks. Jake On 8/23/07, Charlie Groves <cha...@gm...> wrote: > > inspect has been added to Jython 2.2, so you should be able to import > it with that version. > > Charlie > > On 8/23/07, Don Coleman <dco...@ch...> wrote: > > Your import failed because inspect.py is not included with Jython 2.1. > > For jythonconsole I used inspect.py from CPython 2.2.2. > > > > On 8/22/07, Jake B <ota...@gm...> wrote: > > > Just a quick note: > > > I tried import inspect under jython 2.2rc3, and it works fine, but it > fails > > > under jython 2.1. > > > Is this normal? > > > Please let me know. Thanks. > > > > > > Jake > > > > > > > > > On 8/22/07, Jake B <ota...@gm...> wrote: > > > > Thank you for the quick replies! Jythonconsole is very interesting. > Also, > > > I found that the commercial version of Pydev supports some > autocompletion > > > and autoimports libraries. Unfortunately, Pydev autocompletion doesn't > work > > > perfectly, and jythonconsole does not yet adequately fulfill my needs > for an > > > editing environment. > > > > For now, I'd just be happy to have the inspect module working. The > > > developer of jythonconsole says that he uses inspect.py in his > > > implementation, but whenever i'm using jython and I try to import it, > I > > > always get an error message saying that the module cannot be found. > When I'm > > > in python, however, I'm able to import it just fine. > > > > If anyone has any advice as to how I could troubleshoot this, I > would > > > greatly appreciate it if you would let me know. Thanks. > > > > > > > > Jake > > > > > > > > > > > > > > > > On 8/21/07, Pekka Laukkanen <pe...@ik...> wrote: > > > > > 2007/8/21, Jake B < ota...@gm...>: > > > > > > I was wondering if there > > > > > > were any other function that could retrieve an object's public > methods > > > and > > > > > > other constructs. > > > > > > > > > > You probably already know about it but simply using dir(object) > gives > > > > > you list of all the object's attributes. If you are only > interested > > > > > about methods, relatively simple code like below can help. > > > > > > > > > > >>> from java.lang import String > > > > > >>> from types import MethodType > > > > > >>> s = String('') > > > > > >>> for a in [a for a in dir(s) if type(getattr(s, a)) is > MethodType ]: > > > > > ... print a > > > > > > > > > > > > > > > Cheers, > > > > > .peke > > > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------- > > > This SF.net email is sponsored by: Splunk Inc. > > > Still grepping through log files to find problems? Stop. > > > Now Search log events and configuration files using AJAX and a > browser. > > > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > > _______________________________________________ > > > Jython-users mailing list > > > Jyt...@li... > > > https://lists.sourceforge.net/lists/listinfo/jython-users > > > > > > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by: Splunk Inc. > > Still grepping through log files to find problems? Stop. > > Now Search log events and configuration files using AJAX and a browser. > > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > _______________________________________________ > > Jython-users mailing list > > Jyt...@li... > > https://lists.sourceforge.net/lists/listinfo/jython-users > > > |
From: Don C. <dco...@ch...> - 2007-08-23 18:16:47
|
I think this is "normal" inspect.getmembers is calling getattr on attributes that are not readable from javax.swing import JFrame from java.awt import IllegalComponentStateException frame = JFrame() for key in dir(frame): try: getattr(frame, key) print key except (TypeError, AttributeError, IllegalComponentStateException), e: print "%s [NOT READABLE %s]" % (key, e.__class__) On 8/23/07, Jake B <ota...@gm...> wrote: > You are correct, I am able to import inspect with Jython 2.2. It doesn't > seem to work on all classes though. For example, I can do this, and > everything is happy: > > Jython Completion Shell > JythJython Completion Shell > Jython 2.2 on java1.5.0_10 > >>> import inspect > >>> class Test: > ... def testMethod(): > ... print 'foo' > ... > >>> t = Test() > >>> t > <<unknown>.Test instance 1> > >>> inspect.getmembers(t,inspect.ismethod) > [('testMethod', <method Test.testMethod of Test instance 1>)] > > But if I try the same thing with a JFrame, it doesn't work: > > >>> from javax.swing import JFrame > >>> f = JFrame() > >>> f > javax.swing.JFrame[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane= > javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true] > >>> inspect.getmembers (f,inspect.ismethod) > Traceback (most recent call last): > File "<input>", line 1, in ? > File > "/mathworks/home/jbeard/jythonconsole-0.0.4/inspect.py", > line 160, in getmembers > value = getattr(object, key) > TypeError: write only attribute > > Is this normal? Could anyone explain why this is happening? > Please let me know. Thanks. > > Jake > > > On 8/23/07, Charlie Groves <cha...@gm...> wrote: > > inspect has been added to Jython 2.2, so you should be able to import > > it with that version. > > > > Charlie > > > > On 8/23/07, Don Coleman <dco...@ch... > wrote: > > > Your import failed because inspect.py is not included with Jython 2.1. > > > For jythonconsole I used inspect.py from CPython 2.2.2. > > > > > > On 8/22/07, Jake B < ota...@gm...> wrote: > > > > Just a quick note: > > > > I tried import inspect under jython 2.2rc3, and it works fine, but it > fails > > > > under jython 2.1. > > > > Is this normal? > > > > Please let me know. Thanks. > > > > > > > > Jake > > > > > > > > > > > > On 8/22/07, Jake B <ota...@gm...> wrote: > > > > > Thank you for the quick replies! Jythonconsole is very interesting. > Also, > > > > I found that the commercial version of Pydev supports some > autocompletion > > > > and autoimports libraries. Unfortunately, Pydev autocompletion doesn't > work > > > > perfectly, and jythonconsole does not yet adequately fulfill my needs > for an > > > > editing environment. > > > > > For now, I'd just be happy to have the inspect module working. The > > > > developer of jythonconsole says that he uses inspect.py in his > > > > implementation, but whenever i'm using jython and I try to import it, > I > > > > always get an error message saying that the module cannot be found. > When I'm > > > > in python, however, I'm able to import it just fine. > > > > > If anyone has any advice as to how I could troubleshoot this, I > would > > > > greatly appreciate it if you would let me know. Thanks. > > > > > > > > > > Jake > > > > > > > > > > > > > > > > > > > > On 8/21/07, Pekka Laukkanen < pe...@ik...> wrote: > > > > > > 2007/8/21, Jake B < ota...@gm...>: > > > > > > > I was wondering if there > > > > > > > were any other function that could retrieve an object's public > methods > > > > and > > > > > > > other constructs. > > > > > > > > > > > > You probably already know about it but simply using dir(object) > gives > > > > > > you list of all the object's attributes. If you are only > interested > > > > > > about methods, relatively simple code like below can help. > > > > > > > > > > > > >>> from java.lang import String > > > > > > >>> from types import MethodType > > > > > > >>> s = String('') > > > > > > >>> for a in [a for a in dir(s) if type(getattr(s, a)) is > MethodType ]: > > > > > > ... print a > > > > > > > > > > > > > > > > > > Cheers, > > > > > > .peke |