bbartling
bbartling

Reputation: 3514

parsing strings with Parse package

I am attempting to create a program with a console input and parse the text input.

import parse


while True:

    def parse_text(text: str) -> str:
        result = parse.parse(text)
        return str(result)

    answer = input('Which type of component do you need help with, an AHU or VAV?')
    name = parse_text(answer)
    if {name} == 'VAV':
        print('Ok, what VAV number?')
    if {name} == 'AHU':
        print('Ok, what AHU number?')
    else:
        print('Please specify AHU or VAV')

I have a feeling the function parse_text isnt returning a string, can someone give me a tip?

Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
========== RESTART: C:/Users/benb/Desktop/text_parse/parse_hvac.py ==========
Which type of component do you need help with, an AHU or VAV?AHU
Traceback (most recent call last):
  File "C:/Users/benb/Desktop/text_parse/parse_hvac.py", line 13, in <module>
    name = parse_text(answer)
  File "C:/Users/benb/Desktop/text_parse/parse_hvac.py", line 9, in parse_text
    result = parse.parse(text)
TypeError: parse() missing 1 required positional argument: 'string'
>>> 

Upvotes: 0

Views: 64

Answers (1)

luis.parravicini
luis.parravicini

Reputation: 1227

parse needs two arguments, look at https://github.com/r1chardj0n3s/parse

If the input function you call is the one provided by Python, why don't you just do

name = answer.upper()
if name == 'VAV':
    print('Ok, what VAV number?')

Upvotes: 1

Related Questions