python - Stripping Commas and Periods -


I am currently trying to input a text file, I separate each word and arranged it in the list. I am here.

The current problem I am doing is getting rid of commas and periods from the text file.

My code is below:

  #Process a '* .txt' file. Def process (): name = input ("What is the name of the file that you want to read?") File = open (name, "r") text = [word in the line in line for the word in the line. () .split ()] word = word Location (",", "") word = word Location (".", "") Print (text)   

I am currently in the output:

  ['this', 'is', 'The', 'first', 'line', 'key', 'the', 'file. As you can see, the word "file" and "line" have the same one, as you can see, "file" and "row"  

I am reading the text file:

This is the first line of the file.

This is the second line.

Thanks in advance.

These lines have no effect

  word = word. Location (",", "") word = word Change your list to this list:  
  [word.replace (",", "" " ). For line in the file for the line in the line (".", "") Less () Partition ()]    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -