Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20552
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Neil Cerutti <neilc@norwich.edu> |
| Newsgroups | comp.lang.python |
| Subject | Re: Undoing character read from file |
| Date | 17 Feb 2012 13:12:07 GMT |
| Organization | Norwich University |
| Lines | 22 |
| Message-ID | <9q7217F6j0U3@mid.individual.net> (permalink) |
| References | <CAOypoo53NuLCfju_YuYh6AHR4g0GuN=EbKnmh7KY-3nxbaOSLg@mail.gmail.com> <mailman.5904.1329435244.27778.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net 3gBO52OR7LU9tewDbsgIEw8j0PlsKzLkVHuvZ3cAAcidX7YTWH |
| Cancel-Lock | sha1:psUtkojPBW7FeV5kQglOgH3B3Mo= |
| User-Agent | slrn/0.9.9p1/mm/ao (Win32) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:20552 |
Show key headers only | View raw
On 2012-02-16, MRAB <python@mrabarnett.plus.com> wrote: > On 16/02/2012 23:10, Emeka wrote: >> Hello All, >> >> I know about seek and tell while using readline. What about if I am >> using read, and I want to undo the last character I just read(to return >> it back to the stream). How do I achieve this? >> > Try: > > f.seek(-1, 1) > > It seeks -1 relative to the current position (the second > argument defaults to 0 for relative to start of file). Unless it's a stream opened in binary mode this will not work. You'd need to maintain a n-character length buffer instead, with n being the maximum number of characters you'd like to be able to put back. -- Neil Cerutti
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Undoing character read from file MRAB <python@mrabarnett.plus.com> - 2012-02-16 23:31 +0000
Re: Undoing character read from file Neil Cerutti <neilc@norwich.edu> - 2012-02-17 13:12 +0000
Re: Undoing character read from file Dave Angel <d@davea.name> - 2012-02-17 22:58 -0500
csiph-web