以下是我的任务依据: 编写一个通过textfile.txt读取的脚本。该脚本将创建一个名为textfile-selected-words.txt的文件。新的textfile-selected-words.txt文件应包含textfile.txt中包含字母'j'的所有单词,大写或小写。如果textfile.txt中的单词不包含字母'j',则会被“忽略”。 我将使用文件对象的readline方法。还建议使用in运算符。
这是我能够提出的,但是新的textfile-selected-words.txt文件正在创建但不包含任何内容。我不知道我错过了哪一步。
f = open('textfile.txt')
h = open('textfile-selected-words.txt', 'w')
line = f.readline()
while line:
if 'j' in line and 'J' in line:
h.write()
line = f.readline()
f.close()
h.close()