String Manipulation

Larry Bates lbates at syscononline.com
Wed Jul 13 11:05:35 EDT 2005


Use .replace function to replace punctuation (you didn't say
exactly what that means but just to get you started):

#
# Extend this list as needed
#
punctuations=',.;:()'
#
# Open input and output files
#
ifp=open(inputfilename,'r')
ofp=open(outputfilename,'w')
#
# Strip out the punctuation characters
#
for line in ifp:
    for punctuation in punctuations:
        line=line.replace(punctuation,'')
	ofp.write(line)

#
# I'll leave the other part for homework but
# you will need to use the .find method of the string
#

ifp.close()
ofp.close()

Larry Bates


Michael Jordan wrote:
> i'll be straight with you and say that this is a homework assignment.
> ive tried to figure it out on my own but am now out of time.
> 
> i need to go through a .txt file and get rid of all punctuation.  also,
> every time i see the work "Fruitloops=1" or "Hamburgers=x" where x is
> ANY number i need to get rid of that also.  thanks a bunch.  hurry
> please!
> 
> jen :)
> 



More information about the Python-list mailing list