how to replace line on particular line in file[no need to write it back whole file again]
Peter J. Holzer
hjp-python at hjp.at
Fri Oct 12 15:00:45 EDT 2018
On 2018-10-11 09:01:55 -0400, Dennis Lee Bieber wrote:
> On Thu, 11 Oct 2018 15:14:49 +0530, Iranna Mathapati
> <iranna.gani28 at gmail.com> declaimed the following:
> >How to replace particular line text with new text on a file
> >i have below code but its writing whole code.
> >
> For C-style streams (which seem to have taken over every operating
> system) in which "lines" are determined by specific characters in the
> stream, you can only "replace" a line IF THE REPLACEMENT IS THE EXACT SAME
> SIZE! If there is any difference in length of the input and output lines,
> you have to read/write everything from the line to the end of the file.
>
> I emphasize "C-style streams" as there were operating systems that did
> support other file organizations natively.
And therefore you should call them "Unix-style streams".
> Xerox CP-V offered "consecutive", "keyed", and "random" file
> organizations.
I don't know if there was a C implementation for CP-V, but there is
certainly nothing in the C standard which would prevent a standard
conforming implementation of those file organizations.
hp
--
_ | Peter J. Holzer | we build much bigger, better disasters now
|_|_) | | because we have much more sophisticated
| | | hjp at hjp.at | management tools.
__/ | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20181012/419a4f60/attachment.sig>
More information about the Python-list
mailing list