By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,290 Members | 1,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,290 IT Pros & Developers. It's quick & easy.

need help regarding compilation

P: n/a
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
Share this Question
Share on Google+
7 Replies

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
>
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

P: n/a
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

P: n/a
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

P: n/a

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.