[Tutor] striping whitespace from files

kumar s ps_python at yahoo.com
Sat Jul 10 13:07:50 CEST 2004

Hi all , 
 I am learning programming using python. I have a
question about striping white spaces from a file. my
logic is that each element of the list [i] iterates
and the whitespace it encounters is stripped by strip
I do not know where I am going wrong. Is my logic
incorrect or it is the way that my syntax is wrong. 
Can any one please help.
Thank you. 


>>> f1 = open("citrate.txt",'r')
>>> f2 = f1.read()
>>> from string import strip, split
>>> f2 = f1.readlines()
>>> list = split(f2,'\n')
>>> for i in fstrings:
	f1strings = string.split([i])
	print f1strings


Traceback (most recent call last):
  File "<pyshell#86>", line 2, in -toplevel-
    f1strings = string.split([i])
  File "C:\Python23\lib\string.py", line 121, in split
    return s.split(sep, maxsplit)
AttributeError: 'list' object has no attribute 'split'

Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!

More information about the Tutor mailing list