Отображение результатов pyparsing путем разметки кавычек и квадратных скобок - PullRequest
0 голосов
/ 17 ноября 2018

Как я могу удалить кавычки и квадратные скобки из результатов проанализированных результатов, чтобы я мог сохранить их в БД для выполнения аналитики

код питона:

     #!/bin/python
     import pyparsing as pp
     from pyparsing import *
     import string


     # define the grammar for the log file
     integer = Word(nums)
     day = Word(alphas)

     # example log line
     log_display = ("[7]")

     # type of record
     ut_type = "[" + Word(nums) + "]"

     # combine the grammar
     log = ut_type 

     data = log.parseString(log_display)
     print(data)

     display_type = None

     def results(log):
          display_type = ut_type.setResultsName("Type of 
                         Record").setParseAction(removeQuotes)
          print(display_type)
          return display_type

     print("outside the function")
     print(display_type)

вывод при запуске кода:

     $python test.py 
     ['[', '7', ']']
     outside the function
     None

Я бы хотел получить вывод: -

 Type of Record: 7

1 Ответ

0 голосов
/ 17 ноября 2018

Вы можете использовать функцию замены строки, чтобы удалить символы из строки.

data.replace("[","").replace("]","").replace("\"","")
...