Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89978
| Date | 2015-05-05 13:10 -0400 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| Subject | Re: Step further with filebasedMessages |
| References | <87oalzh0d5.fsf@Equus.decebal.nl> <mailman.123.1430824107.12865.python-list@python.org> <877fsngi7i.fsf@Equus.decebal.nl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.128.1430845859.12865.python-list@python.org> (permalink) |
On 05/05/2015 11:25 AM, Cecil Westerhof wrote: > > I have a file with quotes and a file with tips. I want to place random > messages from those two (without them being repeated to soon) on my > Twitter page. This I do with ‘get_random_message’. I also want to put > the first message of another file and remove it from the file. For > this I use ‘dequeue_message’. > Removing lines from the start of a file is an n-squared operation. Sometiomes it pays to reverse the file once, and just remove from the end. Truncating a file doesn't require the whole thing to be rewritten, nor risk losing the file if the make-new-file-rename-delete-old isn't quite done right. Alternatively, you could overwrite the line, or more especially the linefeed before it. Then you always do two readline() calls, using the second one's result. Various other games might include storing an offset at the begin of file, so you start by reading that, doing a seek to the place you want, and then reading the new line from there. Not recommending any of these, just bringing up alternatives. -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Step further with filebasedMessages Cecil Westerhof <Cecil@decebal.nl> - 2015-05-05 10:52 +0200
Re: Step further with filebasedMessages Chris Angelico <rosuav@gmail.com> - 2015-05-05 19:20 +1000
Re: Step further with filebasedMessages Cecil Westerhof <Cecil@decebal.nl> - 2015-05-05 12:14 +0200
Re: Step further with filebasedMessages Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-05 20:41 +1000
Re: Step further with filebasedMessages Cecil Westerhof <Cecil@decebal.nl> - 2015-05-05 13:27 +0200
Re: Step further with filebasedMessages Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-05 07:57 -0600
Re: Step further with filebasedMessages Cecil Westerhof <Cecil@decebal.nl> - 2015-05-05 16:51 +0200
Re: Step further with filebasedMessages Peter Otten <__peter__@web.de> - 2015-05-05 13:08 +0200
Re: Step further with filebasedMessages Cecil Westerhof <Cecil@decebal.nl> - 2015-05-05 17:25 +0200
Re: Step further with filebasedMessages Dave Angel <davea@davea.name> - 2015-05-05 13:10 -0400
csiph-web