Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #89895

Why do I get SyntaxError: invalid syntax

From Cecil Westerhof <Cecil@decebal.nl>
Newsgroups comp.lang.python
Subject Why do I get SyntaxError: invalid syntax
Organization Decebal Computing
Date 2015-05-04 13:31 +0200
Message-ID <87d22gk29n.fsf@Equus.decebal.nl> (permalink)

Show all headers | View raw


While copying pasting code to test, the following works:
    from itertools  import islice
    from os         import rename
    from os.path    import expanduser, split
    from tempfile   import NamedTemporaryFile

    real_file = (expanduser('~/Twitter/testing.txt'))
    (filepath,
     file)      = split(real_file)
    with NamedTemporaryFile(mode = 'w', prefix = file + '_', dir = filepath, delete = False) as tf:
        tempfile = tf.name
        with open(real_file, 'r') as f:
            for line in islice(f, 1, None):
                tf.write(line)

    rename(tempfile, real_file)

But first I used:
    from itertools  import islice
    from os         import rename
    from os.path    import expanduser, split
    from tempfile   import NamedTemporaryFile

    real_file = (expanduser('~/Twitter/testing.txt'))
    (filepath,
     file)      = split(real_file)
    with NamedTemporaryFile(mode = 'w', prefix = file + '_', dir = filepath, delete = False) as tf:
        tempfile = tf.name
        with open(real_file, 'r') as f:
            for line in islice(f, 1, None):
                tf.write(line)
    rename(tempfile, real_file)

But that gave:
      File "<stdin>", line 6
        rename(tempfile, real_file)
             ^
    SyntaxError: invalid syntax

Why?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Why do I get SyntaxError: invalid syntax Cecil Westerhof <Cecil@decebal.nl> - 2015-05-04 13:31 +0200
  Re: Why do I get SyntaxError: invalid syntax Chris Angelico <rosuav@gmail.com> - 2015-05-04 22:07 +1000
    Re: Why do I get SyntaxError: invalid syntax Cecil Westerhof <Cecil@decebal.nl> - 2015-05-04 15:16 +0200

csiph-web