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)
Given an input file that contains the following: That specifies the
text, then the output, and the number of times to be repeated
for example: Scenario: Script supports the HEADER command
Given a file named "headercmd" with:
"""
HEADER "THIS IS A \t\t\tHEADER\n"
STRING "just a string\n"
"""
When I run `../bin/filemaker headercmd headeroutput 2`
Then the file "headeroutput" should contain:
"""
This is a header
just a string
just a string
"""
so it will search through the text file, find the key word "header" then print out that header command once
then it will read the keyword STRING and print what comes after the keyword and loop that number of times specified by the user input.. this is the code I have right now..
import sys import re # read command line arguments inpFile = "in.txt" outFile = "out.txt" outFile2 = "out2.txt" count = 3 # Open output file in write mode out = open(outFile,'w') # f=open(inpFile,'r') # l=f.readlines() # l[0] # f3=open(outFile2,'w') # f3.write(l[0].decode('string_escape')) # print(f3) with open(inpFile) as f: # for each line for line in f: # if there is word STRING in line if "HEADER" in line: # Writing to out file # multiplying by count for printing multiple times out.write(str(re.findall(r'"(.*?)"', line, re.DOTALL)[0]).replace('\\n', '\n')) # closing the out file # read input file with open(inpFile) as f: # for each line for line in f: # if there is word STRING in line if "STRING" in line: # Writing to out file # multiplying by count for printing multiple times out.write('"""') out.write('\n') out.write(str(re.findall(r'"(.*?)"', line, re.DOTALL)[0]).replace('\\n', '\n') * count) out.write('"""') # closing the out file out.close()
""" Author: Date :17/3/17 File Name:filemaker.py Description: """ import sys import re # read command line arguments # arg[0] is .py file inpFile = sys.argv[1] outFile = sys.argv[2] count = int(sys.argv[3]) # Open output file in write mode out = open(outFile, 'w') with open(inpFile) as f: # for each line out.write('"""\n') for line in f: # if there is word STRING in line if "HEADER" in line: # Writing to out file # multiplying by count for printing multiple times string_data = str(re.findall(r'"(.*?)"', line, re.DOTALL)[0]).replace('\\n', '\n').replace("\\t", "\t") out.write(string_data) # read input file with open(inpFile) as f: # for each line for line in f: # if there is word STRING in line if "STRING" in line: # Writing to out file # multiplying by count for printing multiple times out.write('\n') out.write(str(re.findall(r'"(.*?)"', line, re.DOTALL)[0]).replace('\\n', '\n') * count) out.write('"""') # closing the out file out.close()
out.txt
Note: if have you have \t in file then you shoud replace with \t then it will work beacuse when you read "\t" treated as string but when you replace with "\t" its treated as whitespace
if any doubt please comment (its confusing )
I cant get this python program to read all the unique words in a file. It can only read the number of the unique words in a line. import re import string from collections import Counter # opens user inputted filename ".txt" and (w+) makes new and writes def main(): textname = input("Enter the file to search: ") fh = open(textname, 'r', encoding='utf-8' ) linecount = 0 wordcount = 0 count = {} print("Sumary of the", fh) for line in...
I need help understanding this programming assignment. I do not understand it at all. Someone provided me with the code but when I run the code on eclipse it gives an error. Please explain this assignment to me please. Here is the code: import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class TextEditor { public static List<String> lines = new ArrayList<String>(); public static void main(String[] args) throws IOException { Scanner s = new...
Python Problem Hello i am trying to finish this code it does not save guesses or count wrong guesses. When printing hman it needs to only show _ and letters together. For example if the word is amazing and guess=a it must print a_a_ _ _ _ not a_ _ _ _ and _a_ _ _ separately or with spaces. The guess has a maximum of 8 wrong guesses so for every wrong guess the game must count it if...
Hi, can someone offer input on how to address these 4 remain parts the zybook python questions? 4: Tests that get_num_items_in_cart() returns 6 (ShoppingCart) Your output ADD ITEM TO CART Enter the item name: Traceback (most recent call last): File "zyLabsUnitTestRunner.py", line 10, in <module> passed = test_passed(test_passed_output_file) File "/home/runner/local/submission/unit_test_student_code/zyLabsUnitTest.py", line 8, in test_passed cart.add_item(item1) File "/home/runner/local/submission/unit_test_student_code/main.py", line 30, in add_item item_name = str(input('Enter the item name:\n')) EOFError: EOF when reading a line 5: Test that get_cost_of_cart() returns 10 (ShoppingCart)...
Theres an error on The bolded line, what am I doing wrong? #include <iostream> //just for writing and reading from console #include <fstream> //this one to deal with files, read and write to text files using namespace std; int main() { //first thing we need to read the data in the text file //let's assume we have the reading in a text file called data.txt //so, we need a stream input variable to hold this data ifstream infile; //now we...
I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...
//I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...
Using python 3.6 How do I incorporate 0 or negative input to raise an error and let the user try again? like <=0 #loop to check valid input option. while True: try: choice = int(input('Enter choice: ')) if choice>len(header): print("Invalid choice!! Please try again and select value either:",end=" ") for i in range(1,len(header)+1): print(i,end=",") else: break choice = int(input('\nEnter choice: ')) except ValueError as ve:print('Invalid response, You need to select the number choice from the option menu') # Catch your...
Python Error: Writing a program to complete the following: Prompt the user for the name of an input file. Open that file for input. (reading) Read the file using a "for line in a file" loop For each line, o print the line and compute and print the average word length for that line. Close the input file Sample output: MY CODE IS WRONG AND NEED HELP CORRECTING IT!!! ------------------------------------------------------------------------------------------------------------------------ DESIRED OUTPUT: Enter input file name: Seasons.txt Thirty days hath September...
Write a Python program to read lines of text from a file. For each word (i.e, a group of characters separated by one or more whitespace characters), keep track of how many times that word appears in the file. In the end, print out the top twenty counts and the corresponding words for each count. Print each value and the corresponding words, in alphabetical order, on one line. Print this in reverse sorted order by word count. You can assume...