469,953 Members | 2,044 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,953 developers. It's quick & easy.

need help regarding compilation

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.

Feb 23 '06 #1
7 1290
fi****@gmail.com wrote:
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
Feb 23 '06 #2
fi****@gmail.com wrote:
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

Feb 23 '06 #3
fi****@gmail.com 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
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Feb 23 '06 #4
>
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:\\Prog ram
Files\\j
ython123\\Tools\\jythonc;C:\\PROGRA~1\\JYTHON~1\\s rc\\.;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

Feb 23 '06 #5
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
!!

Feb 23 '06 #6
fidlee wrote:
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.


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
Feb 23 '06 #7

Kent Johnson wrote:
fidlee wrote:
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.


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?

Feb 23 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by praba kar | last post: by
39 posts views Thread by Steven T. Hatton | last post: by
12 posts views Thread by sunil | last post: by
1 post views Thread by annappa | last post: by
1 post views Thread by ju21 | last post: by
9 posts views Thread by ramsatishv | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.