How to get rid the new line

SiverFish occeanlinux at linuxmail.org
Thu Jun 27 20:14:54 EDT 2002


On Thu, 27 Jun 2002 14:00:22 +0000, Peter Hansen wrote:

> Markus von Ehr wrote:
>> 
>>         f = open(filename, 'r')
>>         lines = f.readlines()
>>         line1 = lines[0] # exemplarily for first line line1 =
>>         line1[0:len(line1)-1]
>> 
>> or:
>>         f = open(filename, 'r')
>>         lines = f.readlines()
>>         line1 = lines[0][0:len(line1)-1] # exemplarily for first line
> 
> I believe this is unsafe.  The final line may not be terminated with \n.
> 
> -Peter
Any method like chomp in perl
I just one to cut read only the line that not empty into the list



More information about the Python-list mailing list