#jython IRC Log (v0.9)

Index

IRC Log for 2014-07-13

Timestamps are in GMT/BST.

[0:07] * enebo (~enebo@c-75-73-8-169.hsd1.mn.comcast.net) has joined #jython
[0:25] * enebo (~enebo@c-75-73-8-169.hsd1.mn.comcast.net) Quit (Quit: enebo)
[2:47] * int3__ (~int3__@175.156.111.160) has joined #jython
[2:51] * int3__ (~int3__@175.156.111.160) Quit (Ping timeout: 240 seconds)
[6:18] * int3__ (~int3__@175.156.111.160) has joined #jython
[6:20] * int3__ (~int3__@175.156.111.160) Quit (Remote host closed the connection)
[8:38] * sidrero (~sidrero@80-219-42-79.dclient.hispeed.ch) has joined #jython
[8:38] <sidrero> hello
[8:39] <sidrero> I have a question
[8:39] <sidrero> If I initialize a list of lists
[8:39] <sidrero> result = [[None,None,None,None]] * 10
[8:39] <sidrero> then I iterate trough it:
[8:40] <sidrero> for x in range(0,10):
[8:40] <sidrero> result[x][3] = x
[8:40] <sidrero> I would expect
[8:40] <sidrero> to have something like
[8:41] <sidrero> [ [None,None,None,0] , [None,None,None,1] ... [None,None,None,9] ]
[8:41] <sidrero> but what I get is
[8:41] <agronholm> no
[8:41] <agronholm> that would mean you have 10 lists originally like [None, None, None, None]
[8:41] <agronholm> but you only have one, linked to then other lists
[8:41] <agronholm> *ten other
[8:42] <sidrero> yes, that's what I want
[8:42] <agronholm> well, that's what you got
[8:42] <sidrero> ok, I am confused
[8:42] <agronholm> you're modifying the same list on every iteration
[8:42] <sidrero> arg
[8:42] <sidrero> I see
[8:43] <sidrero> what would be the correct way of initializing a list of lists
[8:44] <agronholm> result = [[None, None, None, None] for _ in range(10)]
[8:44] <sidrero> for _ ? what is that?
[8:44] <agronholm> it can be anything
[8:44] <sidrero> ah ok
[8:44] <agronholm> it's an unused variable but needs to be there for the syntax
[8:44] <sidrero> ok, I see
[8:45] <sidrero> yes, now it is correct
[8:45] <sidrero> thanks a lot
[8:46] <sidrero> some time ago I posted here another problem I had
[8:47] <sidrero> https://gist.github.com/anonymous/9143580
[8:47] <sidrero> https://gist.github.com/anonymous/9170404
[8:48] <sidrero> basically when creating an array [][] with some null values in Java an then trying to put that into a jython PyList PyList
[8:48] <sidrero> something goes wrong
[8:48] <agronholm> but you can't put nulls in a java array?
[8:48] <sidrero> ?
[8:48] <agronholm> can you?
[8:49] <agronholm> oh, an object array
[8:49] <sidrero> yes
[8:49] <agronholm> so what goes wrong
[8:49] <sidrero> I build the jython List of List
[8:49] <sidrero> if I try to do anything with ti
[8:49] <sidrero> it
[8:49] <sidrero> let's say just printing
[8:49] <sidrero> an error araises
[8:49] <agronholm> in python code?
[8:49] <agronholm> or java
[8:49] <sidrero> any
[8:50] <agronholm> naming variables with a capital first letter is confusing
[8:50] <sidrero> ok, good to know, but I guess that is not the problem
[8:51] <sidrero> I guess should be something very stupid as my previous problem we talked about
[8:51] <sidrero> but just could not figure out
[8:52] <sidrero> Exception in thread "main" java.lang.NullPointerException
[8:52] <sidrero> at org.python.core.PyList.list_toString(PyList.java:464)
[8:52] <sidrero> at org.python.core.PyList.toString(PyList.java:450)
[8:52] <sidrero> at org.python.core.PyObject.__repr__(PyObject.java:174)
[8:52] <sidrero> at org.python.core.PyList.list_toString(PyList.java:464)
[8:52] <sidrero> at org.python.core.PyList.toString(PyList.java:450)
[8:52] <sidrero> at Main.main(Main.java:127)
[8:52] <agronholm> why do you do this in java code?
[8:53] <sidrero> because
[8:53] <sidrero> I have a bigger application in java
[8:53] <sidrero> not mine
[8:53] <sidrero> I am just embedding jython to be able to do some scripting
[8:53] <sidrero> it works well in general
[8:53] <sidrero> except for this damn situation
[8:54] <sidrero> for now I fixed it by passing "" (empty string) instead of None
[8:54] <sidrero> that works well
[8:54] <sidrero> but it would be nicer to be able to have Nones
[8:56] <agronholm> could you reproduce this problem with a less complicated example?
[8:58] <sidrero> hmm
[8:58] <sidrero> I tought it was already quite simple,
[8:58] <sidrero> what do you mean by simpler?
[8:58] <agronholm> simplify it as much as possible while still reproducing it
[8:59] <sidrero> ok, I have to think about that
[8:59] <sidrero> but I guess maybe it is difficult, seems to come in this specific situation
[9:00] <sidrero> trying to do something similar in pure jython for instance does not create a problem
[9:00] <sidrero> either does it in pure java
[9:02] <agronholm> is the loop necessary to reproduce this?
[9:02] <sidrero> aha
[9:02] <sidrero> let me try
[9:04] * int3__ (~int3__@175.156.111.160) has joined #jython
[9:05] <sidrero> removing the most inner for loop already removes the problem
[9:06] <sidrero> ah ok
[9:06] <sidrero> but something interesting happens
[9:06] <sidrero> very interesting indeed
[9:06] <sidrero> this time
[9:06] <sidrero> I have object[] and that is [1,2,None]
[9:06] <sidrero> when I translate to PyList
[9:06] <sidrero> it gives me
[9:07] <sidrero> ah no sorry
[9:07] <sidrero> my mistake
[9:07] <sidrero> rectify: removing the most inner for loop does not solve it
[9:08] <sidrero> still nullpointer exception
[9:08] <sidrero> ok
[9:08] <sidrero> now it is super simple
[9:09] <sidrero> If I create a PyList
[9:09] <sidrero> and add Py.None
[9:09] <sidrero> then the problem comes
[9:09] <sidrero> PyList JythonList = new PyList();
[9:09] <sidrero> JythonList.append(Py.None);
[9:09] <sidrero> System.out.println(JythonList.toString());
[9:09] <sidrero> Exception in thread "main" java.lang.NullPointerException
[9:10] <agronholm> the problem is probably limited to toString()
[9:11] <agronholm> see if python's own __str__() works
[9:12] <sidrero> it does not
[9:14] <sidrero> but you know
[9:14] <sidrero> the original problem was
[9:14] <agronholm> what happens then
[9:14] <sidrero> what happens is this:
[9:14] <sidrero> Exception in thread "main" java.lang.NullPointerException
[9:14] <sidrero> at org.python.core.PyList.list_toString(PyList.java:464)
[9:14] <sidrero> at org.python.core.PyList.toString(PyList.java:450)
[9:14] <sidrero> at org.python.core.PyObject.__repr__(PyObject.java:174)
[9:14] <sidrero> at org.python.core.PyObject.__str__(PyObject.java:207)
[9:14] <sidrero> at Main.main(Main.java:148)
[9:14] <sidrero> but actually, the very original problem I found
[9:15] <sidrero> is that I can construct my PyList of PyLists
[9:15] <sidrero> and I pass it to jython
[9:15] <sidrero> but I have had something like [1,2,None,3]
[9:15] <sidrero> it misteriously become [1,2]
[9:15] <sidrero> anything after the None was missing
[9:16] <sidrero> and I found that trying to print the list already caused a problem
[9:16] <sidrero> so I took that as a simplifation to find the problem
[9:16] <sidrero> but actually I don??t need to print it
[9:16] <sidrero> I don't know if I explain myself well enough, sorry
[9:18] <agronholm> could this be reproduced with a few lines? without any loops?
[9:19] <sidrero> yes
[9:19] <sidrero> three lines
[9:19] <sidrero> PyList JythonList = new PyList();
[9:19] <sidrero> JythonList.append(Py.None);
[9:19] <sidrero> System.out.println(JythonList.__str__());
[9:20] <sidrero> that raises a nullpointerexception
[9:20] <agronholm> please don't name variables with capital letter
[9:20] <agronholm> s
[9:20] <agronholm> it's confusing.
[9:20] <sidrero> oops, sorry
[9:20] <sidrero> jythonList.append(Py.None);
[9:21] <sidrero> System.out.println(jythonList.__str__());
[9:21] <sidrero> forgot jythonList.append(Py.None);
[9:50] <sidrero> is it a bug?
[10:04] <agronholm> can you show me the traceback for that?
[10:04] <agronholm> oh
[10:04] <agronholm> it's the same as what you pasted before?
[10:05] <agronholm> sidrero: what version of jython is this?
[10:08] <sidrero> 2.5.3
[10:09] <sidrero> but I remember to have tried with 2.5.4 and 2.7.x and I also got that
[10:09] <sidrero> this is the traceback:
[10:09] <sidrero> Exception in thread "main" java.lang.NullPointerException
[10:09] <sidrero> at org.python.core.PyList.list_toString(PyList.java:464)
[10:09] <sidrero> at org.python.core.PyList.toString(PyList.java:450)
[10:09] <sidrero> at org.python.core.PyObject.__repr__(PyObject.java:174)
[10:09] <sidrero> at org.python.core.PyObject.__str__(PyObject.java:207)
[10:09] <sidrero> at Main.main(Main.java:148)
[10:10] <agronholm> so what goes wrong here is line 464
[10:10] <agronholm> buf.append(item.__repr__().toString());
[10:10] <agronholm> see what happens with Py.None.__repr__()
[10:11] <sidrero> with repr:
[10:11] <sidrero> Exception in thread "main" java.lang.NullPointerException
[10:11] <sidrero> at org.python.core.PyList.list_toString(PyList.java:464)
[10:11] <sidrero> at org.python.core.PyList.toString(PyList.java:450)
[10:11] <sidrero> at org.python.core.PyObject.__repr__(PyObject.java:174)
[10:11] <sidrero> at Main.main(Main.java:148)
[10:11] <agronholm> so just Py.None.__repr__() does that?
[10:12] <agronholm> the traceback indicates that you did repr() on the list
[10:12] <agronholm> that's not what I asked you to do
[10:12] <sidrero> ah ok, sorry
[10:12] <agronholm> repr() should work properly for PyNone
[10:13] <sidrero> Exception in thread "main" java.lang.NullPointerException
[10:13] <sidrero> at Main.main(Main.java:147)
[10:13] <agronholm> and what did this?
[10:13] <sidrero> Py.None.__repr__();
[10:13] <agronholm> so is Py.None.__repr__ null?
[10:14] <sidrero> I don??t know, it does not want to process that line at all
[10:15] <agronholm> well how about you add a test?
[10:15] <sidrero> it fails, I cannot get a value back
[10:15] <agronholm> if (Py.None.__repr__ == null)
[10:15] <sidrero> let me check
[10:16] <sidrero> nope
[10:16] <sidrero> still causes an error
[10:16] <sidrero> it is not null, it just raises an error, to call __repr__
[10:16] <agronholm> you're saying that just checking for null causes an error?
[10:16] <sidrero> no
[10:16] <sidrero> I am saying that just:
[10:16] <sidrero> Py.None.__repr__() causes an error
[10:17] <agronholm> remind me what is necessary to get the interpreter running
[10:17] <agronholm> from java
[10:17] <sidrero> yep
[10:17] <agronholm> I'll compile a trivial program to reproduce this
[10:17] <sidrero> well, actually at this point I have not initalized the interpreter yet
[10:18] <sidrero> is that relevant?
[10:18] <sidrero> otherwise:
[10:18] <agronholm> haven't initialized?
[10:18] <sidrero> not yet
[10:19] <sidrero> i do this, but only later:
[10:19] <sidrero> Properties sysProps = System.getProperties();
[10:19] <sidrero> Properties postProps = new Properties();
[10:19] <sidrero> sysProps.put("python.home", "C:\\pythonhome\\eclipse workspace\\jython-standalone-2.5.3.jar");
[10:19] <sidrero> String[] argv = new String[0];
[10:19] <sidrero> PythonInterpreter.initialize(sysProps, postProps, argv);
[10:19] <agronholm> don't you think you should be initializing it before you attempt anything else?
[10:19] <sidrero> I don??t see why ... I am using PyList just as any other java class
[10:19] <sidrero> but let me try that
[10:20] <sidrero> oh wow
[10:20] <agronholm> the python stuff depends on the interpreter state
[10:21] <sidrero> I SEE
[10:21] <sidrero> yes, indeed now it seems to be fine
[10:21] <sidrero> let me try now my looping stuff
[10:23] <sidrero> works fine now !!
[10:23] <sidrero> so I always have to initialize the interpreter before working with jython objects in java?
[10:24] <agronholm> yes
[10:24] <sidrero> ahh
[10:24] <sidrero> thanks a lot agronholm
[10:24] <sidrero> I appreciate very much
[10:24] <agronholm> np
[10:25] <agronholm> is there any point in setting python.home if you're using standalone?
[10:25] <sidrero> yes
[10:25] <sidrero> so what happens is
[10:25] <sidrero> I have to embedd it in a eclipse plugin
[10:26] <sidrero> and it has to be only 1 jar because of deployment in our system
[10:26] <sidrero> then I have to put the jython jar inside the jar of the plugin
[10:26] * Arfrever (~Arfrever@apache/committer/Arfrever) has joined #jython
[10:26] <sidrero> and then jython cannot find the libraries
[10:26] <sidrero> so, I have to put a copy of the jython standalone toghether with the scripts and other jars I use as libraries
[10:26] <sidrero> and it reads the standard libraries from there
[10:27] <sidrero> I guess the correct way would be to create two eclipse plugins one with my stuff and another with jython? but in my case it has to be only 1 jar
[10:27] <agronholm> so how does setting python.home help? won't you already have the jython jar in the classpath by then?
[10:27] <sidrero> yes, but for some reason does not find some libraries
[10:27] <sidrero> os for example
[10:27] <sidrero> if I try to import os it fails
[10:28] <sidrero> if I set pythonhome to somewhere else it works
[10:29] <sidrero> sorry, I am very naive, so I had to do this stupid workaround
[10:29] <sidrero> to solve it
[10:30] <sidrero> I remember that importing os failed, also csv
[10:30] <sidrero> but other modules worked, like sys
[10:32] <sidrero> another question regarding initializing the interpreter: now I have the interpreter only in the scope of a method of my class
[10:32] <sidrero> but I have another method which is also working with PyObjects
[10:32] <sidrero> should I then make the interpreter global?
[11:22] <agronholm> sidrero: as opposed to?
[11:46] <sidrero> as opposed to have the interpreter only in the scope of the first method
[11:49] <sidrero> In my toy code, if I take the initialization of the interpreter to another method, and then do my loop stuff in yet another method, it seems to work fine
[11:50] <sidrero> something like:
[11:50] <sidrero> class test {
[11:50] <sidrero> method1: initialize interpreter
[11:51] <sidrero> method2: call method1, then loop trough the pylist
[11:53] <sidrero> yet another question: when I import a module of mine, it gets compiled automatically to myscript$py.class
[11:53] <sidrero> is there a way to supress that behavior? meaning no compiling?
[11:58] <sidrero> what happens is that when I run my script from the java application trough the plugin,
[11:59] <sidrero> I do by importing the script, then it gets compiled
[11:59] <sidrero> if I do any change in the script, it does not take effect at least I manually delete the compiled file
[11:59] <sidrero> therefore would be good to be able to supress that behavior for debugging
[12:07] <sidrero> while keeping it compiled when its ready for production
[13:47] <sidrero> or maybe force to compile again so that the changes are taken
[13:56] * enebo (~enebo@c-75-73-8-169.hsd1.mn.comcast.net) has joined #jython
[14:14] <sidrero> if I use py_compile, would it force to compile the module again?
[15:19] * enebo (~enebo@c-75-73-8-169.hsd1.mn.comcast.net) Quit (Quit: enebo)
[17:04] * sidrero (~sidrero@80-219-42-79.dclient.hispeed.ch) Quit ()
[18:08] * int3__ (~int3__@175.156.111.160) Quit (Read error: Connection reset by peer)
[18:08] * int3__ (~int3__@175.156.111.160) has joined #jython
[18:09] * int3__ (~int3__@175.156.111.160) Quit (Read error: Connection reset by peer)
[18:09] * int3__ (~int3__@175.156.111.160) has joined #jython
[20:33] * int3__ (~int3__@175.156.111.160) Quit (Remote host closed the connection)
[22:04] * int3__ (~int3__@175.156.111.160) has joined #jython

Index

These logs were automatically created by JythonLogBot_ on irc.freenode.net using a slightly modified version of the Java IRC LogBot (github).