Anyone understand this syntax error?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sean Hammond

    #1

    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(i nput):
    .... """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.NamedT emporaryFile()
    .... file.write(inpu t)
    .... file.flush()
    .... return commands.getout put('./markdown.pl '+file.name)
    File "<stdin>", line 15
    return commands.getout put('./markdown.pl '+file.name)
    ^
    SyntaxError: invalid syntax
    >>>
    I don't get it. Syntax seems fine to me, just a normal string
    concatenation.

    --
  • John Machin

    #2
    Re: Anyone understand this syntax error?


    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(i nput):
    ... """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.NamedT emporaryFile()
    ... file.write(inpu t)
    ... file.flush()
    ... return commands.getout put('./markdown.pl '+file.name)
    File "<stdin>", line 15
    return commands.getout put('./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("your file.py").readl ines())

    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

    Comment

    • Peter Otten

      #3
      Re: Anyone understand this syntax error?

      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(i nput):
      ... """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.NamedT emporaryFile()
      ... file.write(inpu t)
      ... file.flush()
      ... return commands.getout put('./markdown.pl '+file.name)
      File "<stdin>", line 15
      return commands.getout put('./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

      Comment

      Working...