ファイル内のテキストが句読点なしで出力されるように、句読点関数を結び付ける必要があります。一線を引く:"How are you today?"
これまでのところ、次のように出力されます。
"how
are
you
today?"
しかし、私はそれを次のように印刷したい:
how
are
you
today
私のコードは次のようになります。
from scanner import *
import sys
import string
def processFile(filename):
s = Scanner(filename)
token = s.readtoken()
array = []
while token != "":
newToken = ""
for i in range(0,len(token),1):
newchar = RawChar(token[i])
newToken = newToken + newchar
array.append(newToken)
token = s.readtoken()
s.close()
return array
def eachLine(tokens):
for i in range(0,len(tokens),1):
pun(tokens[i])
print(tokens[i])
return
def pun(string):
punctuation = ["`","~","!","@","#","$","%","^","&","*","(",")","_","-","+","=","{","[","}","]","|",":",";","\"","'","<",",",">",".","?","/"]
for i in string:
newString = ""
if i not in string:
newString = newString + i
return newString
def RawChar(char):
if char == "A":
char = "a"
elif char == "B":
char = "b"
elif char == "C":
char = "c"
elif char == "D":
char = "d"
elif char == "E":
char = "e"
elif char == "F":
char = "f"
elif char == "G":
char = "g"
elif char == "H":
char = "h"
elif char == "I":
char = "i"
elif char == "J":
char = "j"
elif char == "K":
char = "k"
elif char == "L":
char = "l"
elif char == "M":
char = "m"
elif char == "N":
char = "n"
elif char == "O":
char = "o"
elif char == "P":
char = "p"
elif char == "Q":
char = "q"
elif char == "R":
char = "r"
elif char == "S":
char = "s"
elif char == "T":
char = "t"
elif char == "U":
char = "u"
elif char == "V":
char = "v"
elif char == "W":
char = "w"
elif char == "X":
char = "x"
elif char == "Y":
char = "y"
elif char == "Z":
char = "z"
return char
def main():
newForm = processFile(sys.argv[1])
eachLine(newForm)
main()
?をどこに置くかについての提案はありdef pun(string)
ますか?