我正在尝试创建/学习如何编写一个程序:
我已经能够获得可以收集输入的程序,并在搜索结果上写入一个文件..但到目前为止,在搜索另一个并给出汇总和放大器时,任何工作都没有运气。计数..任何帮助表示赞赏...
到目前为止,这是我的代码:
#!/usr/bin/python
import csv
file = raw_input("Please enter the file name to search: ") #File name
save_file = raw_input("Please enter the file name to save: ") #Save Name
search_string = raw_input("Please type string to search for: ") #search string
#row = raw_input("Please enter column text is in: ") #column number - starts at 0
#ID_INDEX = row
#ID_INDEX = int(ID_INDEX)
f = open(file)
f1 = open(save_file, 'a')
#what looks for the string in the file
copyline=False
for line in f.readlines():
if search_string in line:
copyline=True
if copyline:
f1.write(line)
f1.close() #close saved file
f.close() #close source file