私の質問は、入力ファイルから文字を取り出し、すべてのアルファベット以外の文字をスペース ""に変換し、大文字の文字を別のファイルに書き出します。正規表現などの組み込みライブラリは使用できません。続き は私のコードです英数字以外の文字を取り除き、組み込みのライブラリを使用せずにファイルに書き込む方法
このコードが実行されるが、それは必要条件のように、それは非アルファベットを削除し、大文字 例:内のすべての文字を記述する必要があるファイルをsplit.txtには何も書き込まない#Reading the file
ifile = open('test.txt','r')
#Reading the characters of the file and stripping it by words
data = ifile.read().split()
x = str(data).upper()
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z']
file = open("split.txt",'w')
for char in data:
if char.isalpha():
file.write(char)
else:
char.replace(char,' ')
: - もしtest.txtファイルからの入力が "Hello_Wo!rld"の場合、split.txtファイルの出力は "HELLO WO RLD"になります。
最後の行は実際にファイルに書き込まずに単に 'char'を置き換えます。 – tyteen4a03
また、 'letters'配列 – egur