3
<!DOCTYPE html>
<html>
<head>
  <title>Hello World</title>
  <style type="text/css">
    body {background: #fff;}
  </style>
</head>
<body>
  <h1>Hello World</h1>
    <script type="text/python" src="test.py"/>
      <script type="text/javascript"> 
        window.onload=function(){
            alert("python: " + hello());
        }
    </script>
</body>
</html>

test.py

#!/usr/bin/env python

def hello():
    return "hello"

In TideSDK develop says: [Error] An error occured while paring Python on the page:invalid syntax ,('',2,1,'\r\n')

but this worked!! Why?

    <script type="text/python">
    def hello():
        return "hello"
    </script>
      <script type="text/javascript"> 
        window.onload=function(){
            alert("python: " + hello());
        }
    </script>

I am new to TideSDK, my pc is WIN7 x86 with python2.7.3, TideSDK 1.3.1-beta installed, I have no idea of this problem,Please help.

And I tried change test.py encoding,that's not help

Haozes
  • 352
  • 2
  • 12

5 Answers5

1

We are working on this problem. The newer php we are planning to release with 1.3.2-beta should fix this problem.

Mital Vora
  • 2,199
  • 16
  • 19
1

I have the same issue. Unfortunately, I have yet to find the best fix. However implementing the source code in every html file is completely out of the question for me.

The error is complaining about the line endings. I presume are working in windows like I am, so the line endings are as follows: \r\n. TideSDK wrote a some sort of parser for external python files, but completely neglected windows line ending for whichever reason (and maintained unix style line endings). The \r\n is coming up as strange unparsable grammer and stops reading the rest of the file. Until they fix this glitch, I can only see one option. Change your line endings for all external python files from \r\n to \n.

You can do this either with your favorite IDE if it supports new line replacement. Or if it doesn't support changing your newlines, then you can use a python file to replace all of them like so:

fn = 'main.py'
with file(fn, 'rb') as f:
    data = f.read()
with file(fn, 'wb') as f:
    f.write(data.replace('\r\n', '\n'))

However, if you choose the second route you will be forced to run this script every time you save the file.

If I find a better answer I will let you know.

jakebird451
  • 2,288
  • 4
  • 30
  • 45
  • This worked for me, thanks! Here is how to change the line endings in Aptana (an Eclipse IDE): Open the file you need to convert. Select the menu option: File -> Convert Line Delimiters To -> Unix (LF, \n, *) – tiangolo Jun 26 '13 at 22:12
0

Try removing the #! line from the python file, it's not really useful for TideSDK anyway.

David M.
  • 773
  • 4
  • 13
  • yes, that's strange. on my OSX machine your first solution works perfectly. I don't have easy access to a Windows machine, so I can't test it otherwise. One more suggestion, did you make sure the test.py file started with the "def hello():" and not an empty line? – David M. Feb 06 '13 at 06:28
0

The issue for me was having empty lines before the def action():

I had an import that came first but it didn't seem to like the empty line before the def

mlantz
  • 113
  • 2
  • 5
0

I ran into this problem while using eclipse on Windows. It appears TideSDK python interpreter requires Unix style line delimiters (i.e. the non-printable character(s) that tell the computer to put text on a new line)

Windows uses two characters "\r\n" (carriage-return and line-feed) where as unix uses just the line feed character. So, if you are using a text editor on Widows, most likely it will insert "\r\n" every time you hit "enter" or "return".

If you are using Eclipse as your text editor, the fix is

File -> Convert Line Delimiters To 

and select Unix.

To make the text editor do this for all new files, select "Other" and "Unix" in

Window -> Preferences -> General -> Workspace -> New text file line delimiter.

Hope this helps

splrk
  • 186
  • 1
  • 7