On Apr 1, 6:32 pm, Mark Wooding <[EMAIL PROTECTED]> wrote:
> Paddy <[EMAIL PROTECTED]> wrote:
> > Why not use the fileinput modules functionality to iterate over a file
> > in-place,printing just those lines you want?
>
> From the Python 2.5 manual:
>
> : *Optional in-place filtering:* if the keywo
Paddy <[EMAIL PROTECTED]> wrote:
> Why not use the fileinput modules functionality to iterate over a file
> in-place,printing just those lines you want?
>From the Python 2.5 manual:
: *Optional in-place filtering:* if the keyword argument `INPLACE=1' is
: passed to `input()' or to the `FileInput
On Mar 31, 7:10 pm, Mark Wooding <[EMAIL PROTECTED]> wrote:
> Paul Rubin wrote:
> > You could do it "in place" in all those systems afaik, either opening
> > the file for both reading and writing, or using something like mmap.
> > Basically you'd leave the file unchanged up to line N, then copy li
Paul Rubin wrote:
> You could do it "in place" in all those systems afaik, either opening
> the file for both reading and writing, or using something like mmap.
> Basically you'd leave the file unchanged up to line N, then copy lines
> downward starting from line N+1. At the end you'd use ftrunc
On Mar 29, 11:13 am, eMko <[EMAIL PROTECTED]> wrote:
> Hello,
>
> In Perl, using a Tie::File module I can easily and comfortably delete
> a line from the middle of a text file:
>
> my @file;
> open(DATA, "+<:encoding(utf8):raw" , "file.txt") or return 0;
> tie @file, 'Tie::File', \*DATA or re
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> The only safe way to delete a line from a file (at least under common
> operating systems like Windows, Linux and Mac) is to copy the file
> (without the line you wish to delete) to a temporary file, then replace
> the original file with the new vers
On Sat, 29 Mar 2008 04:13:10 -0700, eMko wrote:
> Is there some easy way how to delete a line from a middle of a file in
> Python?
If the file is small enough to fit into memory (say, up to a few hundred
megabytes on most modern PCs):
lines = open('file', 'r').readlines()
del line[100]
open('f
Hello,
In Perl, using a Tie::File module I can easily and comfortably delete
a line from the middle of a text file:
my @file;
open(DATA, "+<:encoding(utf8):raw" , "file.txt") or return 0;
tie @file, 'Tie::File', \*DATA or return 0;
splice(@file, $_[0], 1);
untie @file;
close DATA;
(w