Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Jython and Python in one File

Tags:

python

jython

I developed a project using python. Now i need a gui for that project. So i choose jython for gui(java swing). I also integrate theme in one code (existing project + gui(jython) code). When i run the file with the following command then it shows a syntax error

jython project.py

Error:

File "project.py", line 33
SyntaxError: 'with' will become a reserved keyword in Python 2.6

Line#33:

32 def _finished_loading(self, view, frame):
33        with open(self._file, 'w') as f:

When i run the existing project with python command then it runs ok. That means there is no problem with the project. And i assure you that gui(jython) code and integration are also fine.

like image 951
shantanu Avatar asked Apr 09 '12 18:04

shantanu


1 Answers

Because with only just appeared in 2.5, you need a from __future__ import:

from __future__ import with_statement

Then you can use your with statement. It won't solve your other problems that cropped up in your comments, though...

like image 152
zigg Avatar answered Sep 28 '22 07:09

zigg