Run Jython and Python in one file

I developed a project using python. Now I need gui for this project. Therefore, I choose jython for gui (java swing). I also integrate the theme into one code (existing project code + gui (jython)). When I run the file with the following command, 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 an existing project using the python command, it works fine. This means that there are no problems with the project. And I assure you that the gui code (jython) and the integration are also great.

+6
source share
1 answer

Since with just appeared in version 2.5, you will need from __future__ import:

 from __future__ import with_statement 

Then you can use the with statement. This will not solve your other problems that have arisen in your comments, though ...

+10
source

Source: https://habr.com/ru/post/912775/


All Articles