我想從字符串中刪除所有的標點,但每當我跑我的程序沒有任何反應......這是我的代碼:如何從Python中的字符串中刪除標點符號?
#OPEN file (a christmas carol)
inputFile = open('H:\Documents\Computing\GCSE COMPUTING\Revision\Practice Prog/christmascarol.txt')
carolText = inputFile.read()
#CONVERT everything into lowercase
for line in carolText:
carolTextlower = carolText.lower()
#REMOVE punctuation (Put a space instead of a hyphened word or apostrophe)
import string
exclude = set(string.punctuation)
noPunctu = carolTextlower.join(ch for ch in carolTextlower if ch not in exclude)
print(noPunctu)
當我運行我的程序,沒有出現
有人可以請幫忙 –
提供更多的細節。你如何運行該程序?你使用的是什麼版本的Python?什麼是'inputFile'? –
我試過了,但有人把它全部刪除了 –