0

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'
>>> 
7
  • there's so many syntax errors it doesn't even look like python Commented Sep 25, 2019 at 13:44
  • which ones @SuperStew? Commented Sep 25, 2019 at 13:46
  • parse_text(text: str) -> str and {name}, and while not incorrect, str(result) is unnecessary Commented Sep 25, 2019 at 13:48
  • The first one is part of the type hints added in 3.5. But {name}.. I don't know what it is. Commented Sep 25, 2019 at 13:51
  • @SuperStew those are called function annotations and they are valid. Read more at python.org/dev/peps/pep-3107 Commented Sep 25, 2019 at 13:51

1 Answer 1

1

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?')
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the link, can you expand or post answer how to fix the issue? Sorry still learning...
See the edited answer. Also, what's the purpose of those curly braces in {name}?
That worked, the curly brackets were from documentation I was trying to follow.
One thing that sort of sucks the program loops thru to the very beginning..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.