473,394 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Anyone understand this syntax error?


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.
>>def markdown_perl(input):
.... """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.

--
Dec 2 '06 #1
2 1837

Sean Hammond wrote:
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.
>def markdown_perl(input):
... """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

Dec 2 '06 #2
Sean Hammond wrote:
>
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.
>>>def markdown_perl(input):
... """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?
>>def f():
.... print "hello" # four spaces before 'print'
.... return 42 # one tab before 'return'
File "<stdin>", line 3
return 42
^
SyntaxError: invalid syntax

Peter
Dec 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: konsu | last post by:
hello, would the experts please help. this script works with no errors: ------------------------------- drop table if exists degree; create table degree (id int unsigned not null...
5
by: Danny Anderson | last post by:
Hola- I didn't get any responses on a previous post, so I am trying to reword my problem and post compile-able code that exhibits the behavior I am describing. On the second iteration of the...
5
by: rashmi | last post by:
Hello All, tp.c:107: error: syntax error before '*' token tp.c:108: warning: function declaration isn't a prototype tp.c:121: error: syntax error before '*' token tp.c:122: warning: function...
4
by: Hai Nguyen | last post by:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage using panel to test myself. I tried to use these code below, which is written in VB, and to transform them to c sharp but I got...
2
by: Jeff Brown | last post by:
OK i have came to the conclusion that since this app will be run on multiple computers that loading a complete database and then updating on exit is a moot point. I have tried several ideas...
40
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the...
19
by: so many sites so little time | last post by:
the table is head the colunm is called body <?php //show_site.php // This script retrieves blog entries from the database. // Address error handing. ini_set ('display_errors', 1);...
8
by: Joshua Moore | last post by:
/* Hi, I was hoping someone could help me with this problem. I did my work and worked my way through the usual compiler messages, but I have run against some problem I can't identify. The compiler...
0
by: Stef Mientki | last post by:
hello, I've syntax error which I totally don't understand: ########## mainfile : import test_upframe2 if __name__ == '__main__': var1 = 33 code = 'print var1 + 3 \n'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.