need help regarding compilation

F

fidlee

i am new to learning jython...


i just tried compiling a small piece of code that is given below:

def fac(x)
if x<=1:return 1
return x*fac(x-1)

on

C:\Program Files\jython\temp>jythonc factor.py

it showed the following error:

processing factor
Traceback (innermost last):
File "C:\Program Files\jython\Tools\jythonc\jythonc.py", line 5, in ?
File "C:\Program Files\jython\Tools\jythonc\main.py", line 298, in
main
File "C:\Program Files\jython\Tools\jythonc\main.py", line 219, in
doCompile
File "C:\Program Files\jython\Tools\jythonc\compile.py", line 195, in
compilef
ile
File "C:\Program Files\jython\Tools\jythonc\compile.py", line 209, in
compile
File "C:\Program Files\jython\Tools\jythonc\SrcGenCompiler.py", line
1079, in
execstring
File "<string>", line 1
def fac(x)
^
SyntaxError: invalid syntax





What may have gone wrong?
I am totally clueless as it is not mentioned in any of the books that I
tried.
 
S

Sybren Stuvel

(e-mail address removed) enlightened us with:
i am new to learning jython...

And to python, obviously
i just tried compiling a small piece of code that is given below:

def fac(x)
if x<=1:return 1
return x*fac(x-1)

You need to write 'def fac(x):'.

Sybren
 
D

Diez B. Roggisch

i am new to learning jython...


i just tried compiling a small piece of code that is given below:

def fac(x)
if x<=1:return 1
return x*fac(x-1)

You really have a book about python that doesn't mention that functions
definitions are closed by a colon? I doubt that...

Try this:

def fac(x):
if x<=1:return 1
return x*fac(x-1)

regards,

Diez
 
P

Peter Hansen

i am new to learning jython...


i just tried compiling a small piece of code that is given below:

def fac(x)
if x<=1:return 1
return x*fac(x-1)

This is invalid Python syntax. Have you gone through the Python
tutorial yet? Doing so is probably a good idea if you haven't.

The problem is that "def" statements must be followed with a colon, like so:

def fac(x):
if x <= 1:
return 1
return x * fac(x-1)

(Note the colon after "def fac(x)". I've also taken the liberty of
reformatting the code slightly make it more readable, but that isn't
necessary to avoid the SyntaxError you were getting.)

-Peter
 
F

fidlee

Try this:

def fac(x):
if x<=1:return 1
return x*fac(x-1)

I am still getting an error in compilation. Would be really thankful if
someone could tell me as to what is going wrong.

processing factor

Required packages:

Creating adapters:

Creating .java files:
factor module

Compiling .java to .class...
Compiling with args: ['C:\\Program Files\\Java\\jre1.6.0\\bin\\javac',
'-classpa
th', 'C:\\Program Files\\jython123\\jython.jar;;.\\jpywork;;C:\\Program
Files\\j
ython123\\Tools\\jythonc;C:\\PROGRA~1\\JYTHON~1\\src\\.;C:\\Program
Files\\jytho
n123\\Lib;C:\\Program Files\\jython123', '.\\jpywork\\factor.java']
1 java.io.IOException: CreateProcess: "C:\Program
Files\Java\jre1.6.0\bin\javac
" -classpath "C:\Program
Files\jython123\jython.jar;;.\jpywork;;C:\Program Files
\jython123\Tools\jythonc;C:\PROGRA~1\JYTHON~1\src\.;C:\Program
Files\jython123\L
ib;C:\Program Files\jython123" .\jpywork\factor.java error=2

Consider using the -C/--compiler command line switch, or setting
the property python.jythonc.compiler in the registry.
ERROR DURING JAVA COMPILATION... EXITING
 
F

fidlee

You really have a book about python that doesn't mention that functions
definitions are closed by a colon? I doubt that...


It is not python but jython. But I dont think that the syntax of both
of them are different.
I managed to download the tutorial of jython from the IBM website. I am
wondering as to how they could put in wrong syntaxes in their tutorials
!!
 
K

Kent Johnson

fidlee said:
I am still getting an error in compilation. Would be really thankful if
someone could tell me as to what is going wrong.

Try running the compiler under Java 1.4, or just run the class in the
jython interpreter without compiling it first. For simple examples like
this you don't need to compile, just run it with
jython factor.py

Kent
 
F

fidlee

Kent said:
Try running the compiler under Java 1.4, or just run the class in the
jython interpreter without compiling it first. For simple examples like
this you don't need to compile, just run it with
jython factor.py

Kent

Thanks. i noticed that it runs. But why is it throwing a compilation
error in my case here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top