Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20552
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Undoing character read from file |
| Date | 2012-02-17 13:12 +0000 |
| Organization | Norwich University |
| Message-ID | <9q7217F6j0U3@mid.individual.net> (permalink) |
| References | <CAOypoo53NuLCfju_YuYh6AHR4g0GuN=EbKnmh7KY-3nxbaOSLg@mail.gmail.com> <mailman.5904.1329435244.27778.python-list@python.org> |
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