Home>

Tell me please, I am writing a parser, but something code does not start at all, I can not understand what a mistake (

Link to tar

Import Tarfile
Import OS.
name_tar= input ('Enter the name of the TAR archive that you need to unpack:') # fio-example.tar.gz
log_file= Input ('Enter the Log file name:') # test.log
Def Reader (name_tar, log_file):
    Try:
        tar= tarfile.open (Name_Tar)
    Except:
        Print ('File' + Name_Tar + 'is missing!')
    tar.exTractall () Extract all
    TAR.Close ()
    # Unpacks the entire archive, that is, the path will be .. \ fio-example \ test.log
    dir_t= os.path.dirname (__ File__)
    log_file_path= os.path.join (Dir_t, 'FIO-EXAMPLE', LOG_FILE)
    Try:
        F= Open (log_file_path, "r")
    Except:
        Print ('file' + Log_file_path + 'is missing!')
# Read Lock File Log
    Lines= F.Readlines ()
    F.Close ()
    LST= []
    Marker= 0 # Find markers of the beginning and end of the block that cut out of the log file
    For s in lines:
            If ("Starting" in S) OR ("{" in s):
                marker += 1
            if (marker== 2):
                Break
            if (marker== 1) and ("starting" not in s):
                LST.APPEND (S.Strip ())
                Print (LST)
    Return LST.
parsed_lst= reader (log_file, name_tar)

Do not even write "Enter the name of the Tar archive that you need to unpack:"?

Эникейщик2021-09-10 14:51:29
  • Answer # 1

    Announcement Functions:

    Def Reader (Name_Tar, Log_file):
    

    Call function:

    parsed_lst= reader (log_file, name_tar)
    

    Find two differences.

  • Answer # 2

    Announcement Functions:

    Def Reader (Name_Tar, Log_file):
    

    Call function:

    parsed_lst= reader (log_file, name_tar)
    

    Find two differences.