Two small problems

Kalle Svensson kalle at gnupung.net
Mon May 7 10:48:57 EDT 2001


Sez Martin Johansson:
> 1. I have i textfile named links.
> and I want to have the first line in that file as a string.
> h.putrequest('GET', '/vss/handpc/nyheter/0,2183,138_nyheter_1022,00.html')
> instead of /vss/handpc and so on I want the first line from the file how
> could I solve this.

Something like

f = open("links")
h.putrequest("GET", f.readline().strip())

perhaps?

> 2. And then I wonder if there is any method that can delete all lines i a
> textfile??
> like f.delete(all)???????

Opening the file in write mode truncates it:

open("file_to_truncate", "w")

will null the file named "file_to_truncate".

There is no way, AFAIK, to delete lines from a file object opened for
reading.

More info on http://python.org/doc/current/lib/bltin-file-objects.html

Peace,
  Kalle
-- 
Email: kalle at gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]




More information about the Python-list mailing list