Sukumar
asked on
unable to compile using jython
Hi,
I'm trying to compile a python program using jython and it's throwing below error
C:\jython2.2.1>jython test.py
Traceback (innermost last):
(no code object) at line 0
File "test.py", line 30
html = html if html else download(url, user_agent).read()
^
SyntaxError: invalid syntax
Below is my python program. Please let me know how to resolve this.
I'm trying to compile a python program using jython and it's throwing below error
C:\jython2.2.1>jython test.py
Traceback (innermost last):
(no code object) at line 0
File "test.py", line 30
html = html if html else download(url, user_agent).read()
^
SyntaxError: invalid syntax
Below is my python program. Please let me know how to resolve this.
I'm unaware of Python or Jython supporting an embeeded if statement such as that line contains. I believe the intention of the code can be realized by the following:
if not html:
html = download(url, user_agent).read()
if not html:
html = download(url, user_agent).read()
To elaborate somewhat, I recognize that the construct you attempted to use is similar to a Java construct which would compile just fine in Java. You seem to be operating on the assumption that Jython is somehow "like" Java. This is actually pretty much untrue. Jython is an implementation of Python and syntactically is pure Python. However, Jython is implemented in Java, which allows it to integrate seamlessly with Java libraries and classes, to run under the Java virtual machine, and to be used in any Java environment. But don't go trying to use Java syntax, it won't like it!
ASKER
@Richard
I did as you said but it's throwing error as below
C:\jython2.2.1>jython test.py
Traceback (innermost last):
(no code object) at line 0
File "test.py", line 30
if not html:
^
SyntaxError: invalid syntax
I did as you said but it's throwing error as below
C:\jython2.2.1>jython test.py
Traceback (innermost last):
(no code object) at line 0
File "test.py", line 30
if not html:
^
SyntaxError: invalid syntax
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect...and after copying my own code to notepad(Windows cista) and re-run again it worked. Also richard, i had a last question.
After running will Jython create some kind of class file like for ex: if we run test.py..will it generate test.class ?
After running will Jython create some kind of class file like for ex: if we run test.py..will it generate test.class ?
It is possible to make Jython do that, but it is not straigtforwards. Here is a tutorial: http://wiki.python.org/jython/JythonMonthly/Articles/September2006/1
ASKER
Open in new window