Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need python help .. I need to know if a user were to input 3 commands to a pro

ID: 3862456 • Letter: I

Question

I need python help .. I need to know if a user were to input 3 commands to a program and run it such as specify:
Usage: ./filemaker INPUTCOMMANDFILE OUTPUTFILE RECORDCOUNT
(./filemaker is the program)( (INPUTCOOMANDFUILE= a text file that contains key words that need to be searched through then decided what to do ) (RECORDCOUNT= number)

This is what I need to do:
Given an input file that contains the following:

for example:
Scenario: Script outputs the correct number of records
Given a file named "smallcmd" with:
"""
STRING "hello, world! "
"""
When I run `../bin/filemaker smallcmd smalloutput 3`
Then the file "smalloutput" should contain:
"""
hello, world!
hello, world!
hello, world!
"""

What i need is for the python program to be able to search the text file, and put it either in a list or a dictionary or both.. It needs to search that file for the if the KEYWORD "STRING" is in that file.. if it is it then needs to match the output that i have shown print only the letters or string that comes after that keyword.. in this case since the user entered the number 3 it has to loop that 3 times.. exactly as the input shows.. please make sure that the output is sent to a textfile

Thanks please ask me to clarify anything

Explanation / Answer

#!/usr/bin/python

import sys


def processFile(inputfile, outfile):
content = []
with open(inputfile, "r") as fp:
for line in fp:
if "STRING" in line:
line = line.split("STRING")[1]
line = eval(line);
line = line.strip()
content.append(line)
with open(outfile, "a") as fp:
for line in content:
fp.write(line + " ")


inputfile = sys.argv[1]
outfile = sys.argv[2]
count = sys.argv[3]
count = int(count)

for i in range(0, count):
processFile(inputfile, outfile)

'''

Sample run

hello, world!                                                                                                                                                                   

hello, world!                                                                                                                                                                   

hello, world!

'''

# link for code https://goo.gl/3v5JEi