Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Command line inputs not printing to Log File
Requirement: print out the command line prompts the user enters into a log file.
Problem: line 38, the prompts don't seem to write to the log file.

#! /usr/bin/env python3

import sys
import os
import argparse
import platform
import logging

if __name__ == "__main__": 
    parser = argparse.ArgumentParser(
        description='File parsing program')
    parser.add_argument('-l', '--log_file',
                        metavar = ' ',
                        help='Log file',
    parser.add_argument('-p', '-parse',
                        metavar = ' ',
                        help="File to parse",
                        required = True,
    parser.add_argument('-s', '-string',
                        metavar = ' ',
                        help="String to search",
                        required = True,
    args = parser.parse_args()
                            '%m/%d/%Y %I:%M:%S %p')                 #logs date and time
        logging.debug('The logging occured in: %s ', __name__)      #logs name of code'The program has started!')                    #prompts start of program'The command line prompts were: 1) log file = %s, 2) parse = %s, and 3) string = %s ',
                     args.string)                                   #logs command line prompts
        print('Could not open log file :(')                         #error message if file not created
normal way to debug an error within try/except block is to print error msg verbatim or disable the try/except block temporary  until you are certain the block works.
In this case the problem is with line#17 and line#22 -> long flags should be '--parse' and '--string'

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Seven Segment Display - QUERY on Multi-line side-by-side printing output ajayachander 3 346 Mar-13-2020, 07:02 AM
Last Post: ajayachander
  My Loop for printing text file goes to infinity Nomex 7 402 Feb-10-2020, 03:13 PM
Last Post: buran
  Printing on same line from 2 functions. Dyefull 2 304 Dec-05-2019, 07:39 AM
Last Post: ndc85430
  finding p's in words of a multi-line text file johneven 5 1,001 Jun-24-2019, 03:41 PM
Last Post: ThomasL
  reading text file and writing to an output file precedded by line numbers kannan 7 2,808 Dec-11-2018, 02:19 PM
Last Post: ichabod801
  SSL Certificate Error when trying to do command-line registration with pypi DeliriousDelight 0 1,065 Dec-06-2018, 09:38 AM
Last Post: DeliriousDelight
  command line calculator Zatoichi 4 1,754 Jan-28-2018, 09:01 PM
Last Post: egslava
  Newly written .txt file not printing Crackity 11 2,388 Oct-20-2017, 06:43 AM
Last Post: gruntfutuk

Forum Jump:

Users browsing this thread: 1 Guest(s)