need help regarding compilation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fidlee@gmail.com

    #1

    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\te mp>jythonc factor.py

    it showed the following error:

    processing factor
    Traceback (innermost last):
    File "C:\Program Files\jython\To ols\jythonc\jyt honc.py", line 5, in ?
    File "C:\Program Files\jython\To ols\jythonc\mai n.py", line 298, in
    main
    File "C:\Program Files\jython\To ols\jythonc\mai n.py", line 219, in
    doCompile
    File "C:\Program Files\jython\To ols\jythonc\com pile.py", line 195, in
    compilef
    ile
    File "C:\Program Files\jython\To ols\jythonc\com pile.py", line 209, in
    compile
    File "C:\Program Files\jython\To ols\jythonc\Src GenCompiler.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.

  • Diez B. Roggisch

    #2
    Re: need help regarding compilation

    fidlee@gmail.co m wrote:
    [color=blue]
    > 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)[/color]

    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

    Comment

    • Peter Hansen

      #3
      Re: need help regarding compilation

      fidlee@gmail.co m wrote:[color=blue]
      > 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)[/color]

      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

      Comment

      • Sybren Stuvel

        #4
        Re: need help regarding compilation

        fidlee@gmail.co m enlightened us with:[color=blue]
        > i am new to learning jython...[/color]

        And to python, obviously
        [color=blue]
        > 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)[/color]

        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

        Comment

        • fidlee

          #5
          Re: need help regarding compilation

          >[color=blue]
          > Try this:
          >
          > def fac(x):
          > if x<=1:return 1
          > return x*fac(x-1)[/color]

          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\\jr e1.6.0\\bin\\ja vac',
          '-classpa
          th', 'C:\\Program Files\\jython12 3\\jython.jar;; .\\jpywork;;C:\ \Program
          Files\\j
          ython123\\Tools \\jythonc;C:\\P ROGRA~1\\JYTHON ~1\\src\\.;C:\\ Program
          Files\\jytho
          n123\\Lib;C:\\P rogram Files\\jython12 3', '.\\jpywork\\fa ctor.java']
          1 java.io.IOExcep tion: CreateProcess: "C:\Program
          Files\Java\jre1 .6.0\bin\javac
          " -classpath "C:\Program
          Files\jython123 \jython.jar;;.\ jpywork;;C:\Pro gram Files
          \jython123\Tool s\jythonc;C:\PR OGRA~1\JYTHON~1 \src\.;C:\Progr am
          Files\jython123 \L
          ib;C:\Program Files\jython123 " .\jpywork\facto r.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

          Comment

          • fidlee

            #6
            Re: need help regarding compilation

            [color=blue]
            > You really have a book about python that doesn't mention that functions
            > definitions are closed by a colon? I doubt that...[/color]


            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
            !!

            Comment

            • Kent Johnson

              #7
              Re: need help regarding compilation

              fidlee wrote:[color=blue][color=green]
              >>Try this:
              >>
              >>def fac(x):
              >> if x<=1:return 1
              >> return x*fac(x-1)[/color]
              >
              >
              > I am still getting an error in compilation. Would be really thankful if
              > someone could tell me as to what is going wrong.[/color]

              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

              Comment

              • fidlee

                #8
                Re: need help regarding compilation


                Kent Johnson wrote:[color=blue]
                > fidlee wrote:[color=green][color=darkred]
                > >>Try this:
                > >>
                > >>def fac(x):
                > >> if x<=1:return 1
                > >> return x*fac(x-1)[/color]
                > >
                > >
                > > I am still getting an error in compilation. Would be really thankful if
                > > someone could tell me as to what is going wrong.[/color]
                >
                > 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[/color]

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

                Comment

                Working...