Josh Juneau | 1 Oct 15:42
Picon

Jython Monthly - Issue #34 - October 1, 2009

The Jython Monthly Newsletter and Jython Podcast for September 2009 are now available!

Jython Monthly Newsletter:  http://wiki.python.org/jython/JythonMonthly/Newsletters/September2009

Jython Podcast:  http://www.jythonpodcast.com

If you have any questions or suggestions, please send them to jythonpodcast <at> gmail.com


Josh Juneau
juneau001 <at> gmail.com
http://jj-blogger.blogspot.com
Twitter ID:  javajuneau

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Jochen Fischer | 1 Oct 14:05

Calling methods in derived classes throws exception when executing scripts via the javax.script api

Hi!

When I execute the following simple script from inside java using the 
java.script api I get aTypeError exception (see below).

#---------------------------
from java.lang import Object

class MyClass(Object):
     def __init__(self, foo):
         print foo

c = MyClass("Hello from Jython")
#---------------------------

If I execute the same script directly from Jython everything works as 
expected. Is there anything wrong in what I'm doing or this this a major 
issue in Jython 2.5.1?

Previously I was using Jython 2.1/2.2.1 inside ANT for scripting. When 
calling this script via the old BSF binding everything works well. But 
starting with Jython 2.5 it is not possible to use the BSF mechanism 
anymore due to the fact that the PyInstance class has been removed. With 
Jython 2.5.x it is necessary to use the scripting API from Java 1.6. 
That works well as long as I'm not deriving any Jython class from a Java 
class.

Can anyone give me a hint to avoid this problem when using Jython 2.5 
from Ant?

Thanks
Jochen

Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
         at 
org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:182)
         at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:43)
         at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:48)
         at 
javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:232)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at 
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
         at org.python.core.PyObject.__call__(PyObject.java:355)
         at org.python.core.PyMethod.__call__(PyMethod.java:215)
         at 
org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
         at org.python.core.PyMethod.__call__(PyMethod.java:206)
         at org.python.core.PyObject.__call__(PyObject.java:397)
         at org.python.core.PyObject.__call__(PyObject.java:401)
         at org.python.pycode._pyx36.f$0(<stdin>:1)
         at org.python.pycode._pyx36.call_function(<stdin>)
         at org.python.core.PyTableCode.call(PyTableCode.java:165)
         at org.python.core.PyCode.call(PyCode.java:18)
         at org.python.core.Py.runCode(Py.java:1204)
         at org.python.core.Py.exec(Py.java:1248)
         at 
org.python.util.PythonInterpreter.exec(PythonInterpreter.java:181)
         at 
org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:89)
         at 
org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:70)
         at 
org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:46)
         at 
org.python.util.InteractiveConsole.push(InteractiveConsole.java:110)
         at 
org.python.util.InteractiveConsole.interact(InteractiveConsole.java:90)
         at org.python.util.jython.run(jython.java:316)
         at org.python.util.jython.main(jython.java:129)
Caused by: Traceback (most recent call last):
   File "<script>", line 7, in <module>
TypeError: org.python.proxies.__main__$MyClass$11(): expected 0 args; got 1

         at 
org.python.core.PyException.fillInStackTrace(PyException.java:70)
         at java.lang.Throwable.<init>(Throwable.java:181)
         at java.lang.Exception.<init>(Exception.java:29)
         at java.lang.RuntimeException.<init>(RuntimeException.java:32)
         at org.python.core.PyException.<init>(PyException.java:46)
         at org.python.core.PyException.<init>(PyException.java:43)
         at org.python.core.PyException.<init>(PyException.java:61)
         at org.python.core.Py.TypeError(Py.java:195)
         at 
org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:195)
         at 
org.python.core.PyReflectedFunction.throwArgCountError(PyReflectedFunction.java:248)
         at 
org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:305)

javax.script.ScriptException: javax.script.ScriptException: TypeError: 
org.python.proxies.__main__$MyClass$11(): expected 0 args; got 1 in 
<script> at line number 7

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
Picon

J2ME access

Hello friends,


I am an experienced Python programmer but new to Jython. I am interested to use J2ME classes from a third party J2ME SDK in my Jython application. Pls let me know is that possible. Also, can I build J2ME applications using Jython?

Regards,
VK
------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Mico Siahaan | 6 Oct 11:02
Picon
Favicon

Jythoon Book & Sphinx

Dear all, I made clone of Jython Book from Kenai Project in my laptop. Then, when I try to build html files
using Sphinx I got error message: 
reST markup error:
C:\Users\mico\Documents\PERSONAL\Ebook\python\jythonbook~jython-book\appendixB.r
st:686: (SEVERE/4) Unexpected section title.

Then Sphinx exit and no html files built. Any ideas?

regards,

Mico

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
Josh Juneau | 6 Oct 13:00
Picon

Re: Jythoon Book & Sphinx

Mico-


Thanks for taking a look at the book, we appreciate it and hope you find it useful.  I just recently added appendixB content to the book and it seems as though there was a markup error in the file.  I've corrected it by removing and re-adding a couple of lines (I think a newline character caused the issue), and tested by building it in my environment.  I've checked the new appendixB.rst into the repository and you can use it in place of your current version.  Once you replace the file then everything should build as expected.

Let me know if you have any further issues.

Tanks

Josh Juneau
juneau001 <at> gmail.com
http://jj-blogger.blogspot.com
Twitter ID:  javajuneau


On Tue, Oct 6, 2009 at 4:02 AM, Mico Siahaan <mico_siahaan <at> yahoo.com> wrote:
Dear all, I made clone of Jython Book from Kenai Project in my laptop. Then, when I try to build html files using Sphinx I got error message:
reST markup error:
C:\Users\mico\Documents\PERSONAL\Ebook\python\jythonbook~jython-book\appendixB.r
st:686: (SEVERE/4) Unexpected section title.

Then Sphinx exit and no html files built. Any ideas?

regards,

Mico




------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
william ratcliff | 6 Oct 23:28
Picon

Re: sys.platform?

Sorry to harp on this again, but if I use java.lang.System.getPropery("os.name"), it will return

u'Windows XP'

whereas sys.platform in CPython will return 
'win32'

In code which checks for platforms, this means that everything has to be rewritten for jython.  Would it be possible to have sys.platform to return the same value as Cpython?


Thanks,
William

On Thu, Aug 13, 2009 at 5:05 PM, Eric Widhalm <eric <at> frog-water.com> wrote:
That's not cool.

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.platform
'win32'

-Eric


At 02:27 PM 8/13/2009, william ratcliff wrote:
Ahh,

I have to go to the java side--thanks!
Btw--just a quick check, are all strings which come from java unicode?


Thanks again,
William

On Thu, Aug 13, 2009 at 4:12 PM, Jeff Emanuel <jemanuel <at> frii.com> wrote:
java.lang.System.getProperty('os.name ')

william ratcliff wrote:
Another question:

In Cpython, I usually use sys.platform to test whether I'm running on windows, linux, or macos.  In jython, sys.platform returns the version of java that it is running under--is there an equivalent command to determine the operating system?


Thanks,
William

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Larry Riedel | 7 Oct 00:11

Re: sys.platform?

> if I use java.lang.System.getPropery("os.name"), it
> will return u'Windows XP' whereas sys.platform in
> CPython will return 'win32'.
>
> In code which checks for platforms, this means
> that everything has to be rewritten for jython.
> Would it be possible to have sys.platform to
> return the same value as Cpython?

I think of Java as a different platform from win32,
if sys.platform is used "to append platform-specific
components to sys.path"

It seems to make like with Jython, platform.system()
would return "Java", in which case platform.java_ver()
could be used to get "osinfo" information, for
applications which care that it is Java on Windows.

Larry

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
Markus Krosche | 7 Oct 09:42

Parsing using Ply and Jython ...

Hello together,

I want to use ply for parsing some expressions. I have downloaded the actual version of ply (http://www.dabeaz.com/ply/) and started to run the "calc.py" example (which comes with the ply-package).

It is not working and the error is:

File "<script>", line 42, in <module>
  File "C:\DATA\download\ply-3.3\ply\lex.py", line 887, in lex
    ldict = get_caller_module_dict(2)
  File "C:\DATA\download\ply-3.3\ply\lex.py", line 436, in get_caller_module_dict
    ldict = f.f_globals.copy()
AttributeError: 'scope' object has no attribute 'copy'

Is this a "jython specific" problem with the lex.py?

Thanks in advance
Markus

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Markus Krosche | 7 Oct 12:03

Again Ply and Jython ...

Hello together,

I figured out something and I want to know the difference between the following two approaches:
(1) I have installed jython and the lastest version of ply (http://www.dabeaz.com/ply/) by running jython.bat setup.py install (which comes with the ply package).
It simply installs the py files inside the 'site-packages' folder.

Then I run the 'calc.py' example which comes with the ply package.

It runs fine. Everything works.


(2) I use Jython in my Java software and I want to use the module lex and yacc (which are part of the ply package).

Here is my code:

public class JythonScriptEngineProvider
{
    public ScriptEngine createEngine(final List<String> pathList)
    {
        PySystemState pySystemState = new PySystemState();
        for(String path: pathList)
        {
            pySystemState.path.append(Py.newString(path));
        }
        Py.setSystemState(pySystemState);
        final ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
        return engine;
    }
}


The pathList argument can be used to set the python path. And I am using the above class as follows:

List<String> pythonPath = new ArrayList<String>();
pythonPath.add("<my path to the jython lib>");
pythonPath.add("<my path to the jython lib>/site-packages");

ScriptEngine scriptEngine = new JythonScriptEngineProvider().createEngine(pythonPath);
scriptEngine.eval("import sys");
scriptEngine.eval("print sys.path");
scriptEngine.eval("import ply.lex as lex");
scriptEngine.eval("print lex");
scriptEngine.eval("lex.lex()");

The same error will result when calling the 'calc.py' example like this:

final String pyFile = "C:/DATA/download/ply-3.3/example/calc/calc.py";
scriptEngine.eval(new FileReader(new File(pyFile)));

The error is:

  File "<script>", line 1, in <module>
  File "C:\DATA\spt_workspace\MEPOtrunk\res\python\site-packages\ply\lex.py", line 887, in lex
    ldict = get_caller_module_dict(2)
  File "C:\DATA\spt_workspace\MEPOtrunk\res\python\site-packages\ply\lex.py", line 436, in get_caller_module_dict
    ldict = f.f_globals.copy()
  AttributeError: 'scope' object has no attribute 'copy'


Where is my mistake? What is the problem inside the code. I guess I am doing something completely wrong. But I did not understand it.

Thank you very much
Markus

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Markus Krosche | 7 Oct 12:56

Re: Again Ply and Jython ...

At least for my application I have solved the problem partly.
If I am not using the ScriptEngine it works.

In my simple test I did the following:

List<String> pythonPath = new ArrayList<String>();
pythonPath.add("<my path to jython lib>");
pythonPath.add("<my path to jython lib>/site-packages");
       
PySystemState pySystemState = new PySystemState();
for(String path: pythonPath)
{
     pySystemState.path.append(Py.newString(path));
}
Py.setSystemState(pySystemState);
PythonInterpreter p = new PythonInterpreter();
p.execfile("C:/DATA/download/ply-3.3/example/calc/calc.py");


The only question is now why it does not work when using the ScriptEngine ...

Best regards
Markus



2009/10/7 Markus Krosche <markus.krosche <at> googlemail.com>
Hello together,

I figured out something and I want to know the difference between the following two approaches:
(1) I have installed jython and the lastest version of ply (http://www.dabeaz.com/ply/) by running jython.bat setup.py install (which comes with the ply package).
It simply installs the py files inside the 'site-packages' folder.

Then I run the 'calc.py' example which comes with the ply package.

It runs fine. Everything works.


(2) I use Jython in my Java software and I want to use the module lex and yacc (which are part of the ply package).

Here is my code:

public class JythonScriptEngineProvider
{
    public ScriptEngine createEngine(final List<String> pathList)
    {
        PySystemState pySystemState = new PySystemState();
        for(String path: pathList)
        {
            pySystemState.path.append(Py.newString(path));
        }
        Py.setSystemState(pySystemState);
        final ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
        return engine;
    }
}


The pathList argument can be used to set the python path. And I am using the above class as follows:

List<String> pythonPath = new ArrayList<String>();
pythonPath.add("<my path to the jython lib>");
pythonPath.add("<my path to the jython lib>/site-packages");

ScriptEngine scriptEngine = new JythonScriptEngineProvider().createEngine(pythonPath);
scriptEngine.eval("import sys");
scriptEngine.eval("print sys.path");
scriptEngine.eval("import ply.lex as lex");
scriptEngine.eval("print lex");
scriptEngine.eval("lex.lex()");

The same error will result when calling the 'calc.py' example like this:

final String pyFile = "C:/DATA/download/ply-3.3/example/calc/calc.py";
scriptEngine.eval(new FileReader(new File(pyFile)));

The error is:

  File "<script>", line 1, in <module>
  File "C:\DATA\spt_workspace\MEPOtrunk\res\python\site-packages\ply\lex.py", line 887, in lex
    ldict = get_caller_module_dict(2)
  File "C:\DATA\spt_workspace\MEPOtrunk\res\python\site-packages\ply\lex.py", line 436, in get_caller_module_dict
    ldict = f.f_globals.copy()
  AttributeError: 'scope' object has no attribute 'copy'


Where is my mistake? What is the problem inside the code. I guess I am doing something completely wrong. But I did not understand it.

Thank you very much
Markus


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

Gmane