Can't run with python file.
<!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 development says: [Error] An error occured while paring Python on the page: invalid syntax ('', 2,1, '\ r \ n')
but it 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 computer is WIN7 x86 with python2.7.3, TideSDK 1.3.1-beta, I have no idea about this issue. Please, help.
And I tried changing the test.py encoding not to help
source to share
I have the same problem. Unfortunately, I have yet to find a better solution. However, the implementation of the source code in each html file is completely out of the question for me.
The error raises complaints about line endings. I believe that they are working in such windows, as I, so the end lines is as follows: \r\n
. TideSDK wrote some kind of parser for external python files, but completely ignored Windows line ending for whatever reason (and supported unix style line endings). \r\n
fits like a weird unrepeatable grammar and stops reading the rest of the file. Until they fix this glitch, I can only see one option. Change line endings for all external python files from \r\n
to \n
.
You can do this either with your favorite IDE if it supports newline replacement. Or if it doesn't support changing newlines, you can use a python file to replace all of them like this:
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 take 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.
source to share
I ran into this problem while using eclipse on Windows. It looks like the Python TideSDK interpreter requires Unix-style line separators (i.e. Non-printable character (s) that say the computer is putting text on a newline)
Windows uses two characters "\ r \ n" (carriage return and straight line), where unix uses only the line character. So, if you are using a text editor for Widows, chances are 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 have your text editor do this for all new files, select "Other" and "Unix" in
Window -> Preferences -> General -> Workspace -> New text file line delimiter.
Hope it helps
source to share