Anyone understand this syntax error?

S

Sean Hammond

Anyone understand this?

Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information..... """Send 'input' (string) to the markdown perl script, and return
the
.... output from markdown (string).
....
.... input: a string of markdown-formatted text, including \n's at
the end
.... of lines, that will be sent to the markdown process.
....
.... returns: a string of valid XHTML from markdown
.... """
.... import tempfile
.... import commands
.... file = tempfile.NamedTemporaryFile()
.... file.write(input)
.... file.flush()
.... return commands.getoutput('./markdown.pl '+file.name)
File "<stdin>", line 15
return commands.getoutput('./markdown.pl '+file.name)
^
SyntaxError: invalid syntax
I don't get it. Syntax seems fine to me, just a normal string
concatenation.

--
 
J

John Machin

Sean said:
Anyone understand this?

Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.... """Send 'input' (string) to the markdown perl script, and return
the
... output from markdown (string).
...
... input: a string of markdown-formatted text, including \n's at
the end
... of lines, that will be sent to the markdown process.
...
... returns: a string of valid XHTML from markdown
... """
... import tempfile
... import commands
... file = tempfile.NamedTemporaryFile()
... file.write(input)
... file.flush()
... return commands.getoutput('./markdown.pl '+file.name)
File "<stdin>", line 15
return commands.getoutput('./markdown.pl '+file.name)
^
SyntaxError: invalid syntax
I don't get it. Syntax seems fine to me, just a normal string
concatenation.

Superficially there is nothing wrong with it. After saving that to a
file and doing the editing necessary to change it from a screen dump to
a script, it loads OK on windows with Python 2.4.3 and 2.5.

It is probably not complaining about the string concatenation. The
caret is positioned at the start of the statement; this would indicate
that the problem is on an earlier line. There was a while back a
strange error that only manifested itself in very large source files
(e.g. those generated by the pywin32 package's makepy routine) and
could be cured by adding trailing spaces to the line before the
allegedly offending line. However that seems to have gone away.

My guess is that the problem is something to do with tabs/spaces or you
have some other invisible character at the start of the return
statement. As the text has been through two mail or news clients, the
problem may have been munged away and I'm not seeing it.

Two sugggestions:
(1) at an interactive prompt:

print repr(open("yourfile.py").readlines())

and eyeball the last few lines for monkey business.

(2) e-mail somebody (like me) a zipped (i.e. e-mail-munging-proof) copy
of your file.

Two other comments on your code:
(1) It's not wise to use "file" as a variable name; it shadows the
built-in file(). Not a problem in this code but it's a bad habit that
could bite you later.
(2) Any good reason for flushing the file instead of closing it?

HTH,
John
 
P

Peter Otten

Sean said:
Anyone understand this?

Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.... """Send 'input' (string) to the markdown perl script, and return
the
... output from markdown (string).
...
... input: a string of markdown-formatted text, including \n's at
the end
... of lines, that will be sent to the markdown process.
...
... returns: a string of valid XHTML from markdown
... """
... import tempfile
... import commands
... file = tempfile.NamedTemporaryFile()
... file.write(input)
... file.flush()
... return commands.getoutput('./markdown.pl '+file.name)
File "<stdin>", line 15
return commands.getoutput('./markdown.pl '+file.name)
^
SyntaxError: invalid syntax
I don't get it. Syntax seems fine to me, just a normal string
concatenation.

--

Are you perhaps mixing tabs and spaces?
.... print "hello" # four spaces before 'print'
.... return 42 # one tab before 'return'
File "<stdin>", line 3
return 42
^
SyntaxError: invalid syntax

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,045
Members
48,769
Latest member
Clifft

Latest Threads

Top