[Tutor] Space the final frontier!
János Juhász
janos.juhasz at VELUX.com
Wed Apr 5 13:06:58 CEST 2006
Hi John,
what do you think about this?
def InplaceReplace(filename):
lines = open(filename, 'r').readlines()
lines = [line.replace(' ', '') for line in lines]
open(filename, 'wt').writelines(lines)
It works well on so small files.
Yours sincerely,
______________________________
János Juhász
> Message: 2
> Date: Tue, 4 Apr 2006 22:33:18 +0100
> From: "John Corry" <john.corry at ntlworld.com>
> Subject: [Tutor] Space the final frontier!
> To: <tutor at python.org>
> Message-ID: <NJBBJJFDELIHANPMHPKACEMPCBAA.john.corry at ntlworld.com>
> Content-Type: text/plain; charset="iso-8859-1"
> Dear All,
> I am having difficulty removing white spaces from my file. The file is
999
> lines long and looks like the sample below:
> 001, new field,dial= 028 90 79 0154, dial=
> 002, borfiled, dial= 02890 618521, dial=
> 003, newcomp, dial=02890419689, dial=
> The program, I am using to import the file does not like the spaces
around
> the numbers. The number should look like the "dial=02890419689" in the
> third line. Thus the sample above should look like:
> 001,newfield,dial=02890790154,dial=
> 002,borfiled,dial=02890618521,dial=
> 003,newcomp,dial=02890419689,dial=
More information about the Tutor
mailing list