Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89895
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!newsfeed.pionier.net.pl!feed.xsnews.nl!border03.ams.xsnews.nl!feeder04.ams.xsnews.nl!feeder02.ams.xsnews.nl!abp001.ams.xsnews.nl!frontend-F10-09.ams.news.kpn.nl |
|---|---|
| From | Cecil Westerhof <Cecil@decebal.nl> |
| Newsgroups | comp.lang.python |
| Subject | Why do I get SyntaxError: invalid syntax |
| Organization | Decebal Computing |
| X-Face | "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR<J%a^F2lh4[N~Yz4 nSp#c+aQo1b5=?HcNEkQ7QzF<])O3X4MDL/AYjys&*mt>,v+Pti8=Vi/Z"g^?b"E |
| X-Homepage | http://www.decebal.nl/ |
| Date | Mon, 04 May 2015 13:31:16 +0200 |
| Message-ID | <87d22gk29n.fsf@Equus.decebal.nl> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:yQDZ8bDbhw5ZXP2ad0WnEO5StJc= |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Lines | 45 |
| NNTP-Posting-Host | 81.207.62.244 |
| X-Trace | 1430739889 news.kpn.nl 20902 81.207.62.244@kpn/81.207.62.244:47125 |
| Xref | csiph.com comp.lang.python:89895 |
Show key headers only | 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 | Next — Next in thread | Find similar | Unroll 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