Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89904
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.tele2net.at!news.panservice.it!feed.xsnews.nl!border01.ams.xsnews.nl!feeder01.ams.xsnews.nl!abp001.ams.xsnews.nl!frontend-F10-16.ams.news.kpn.nl |
|---|---|
| From | Cecil Westerhof <Cecil@decebal.nl> |
| Newsgroups | comp.lang.python |
| Subject | Re: Why do I get SyntaxError: invalid syntax |
| Organization | Decebal Computing |
| References | <87d22gk29n.fsf@Equus.decebal.nl> <mailman.82.1430741264.12865.python-list@python.org> |
| 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 15:16:24 +0200 |
| Message-ID | <87zj5kiitz.fsf@Equus.decebal.nl> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:VTZ4NDTGtZcq/q/clcfPYFJ0HgY= |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Lines | 35 |
| NNTP-Posting-Host | 81.207.62.244 |
| X-Trace | 1430746128 news.kpn.nl 21122 81.207.62.244@kpn/81.207.62.244:47870 |
| Xref | csiph.com comp.lang.python:89904 |
Show key headers only | View raw
Op Monday 4 May 2015 14:07 CEST schreef Chris Angelico: > On Mon, May 4, 2015 at 9:31 PM, Cecil Westerhof <Cecil@decebal.nl> wrote: >> While copying pasting code to test, the following works: [chomp] >> But first I used: 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? > > To clarify: When you say "to test", you mean the interactive > interpreter, right? Yes, that is what I mend. Should have been clearer. > If so, you need to end blocks of text with blank > lines (and not have any blank lines in between). It's because the > parser has to know when to run stuff; when you run a script, it > parses the whole thing and then runs it, but interactively, it has > to work piece-meal. OK, thanks: I understand it now. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.python | Previous | Next — Previous 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