deleting a line from a file

eMko mm007.emko at gmail.com
Sat Mar 29 07:13:10 EDT 2008


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;

(when the first argument of the function ($_[0]) is a number of the
line which should be deleted)

Is there some easy way how to delete a line from a middle of a file in
Python?

Thanks a lot
eMko



More information about the Python-list mailing list