- #1
Eclair_de_XII
- 1,083
- 91
- TL;DR Summary
- Basically, the inquirer module is like a module for advanced forms of user-input, like having the user select from a list, multiple choice, text, etc. Documentation is here.
https://python-inquirer.readthedocs.io/en/latest/
I'm using this user-defined module for an amateur coding project, and I am using 'Text' from the 'inquirer' module. When I am either inputting things, or whenever I am validating things, I always get some sort of error. These errors mainly result whenever I hit the back-space key on my keyyboard. I am reconsidering doing this using the 'raw_input' built-in function to do so, but it would be nice to know how to figure out the source of my problem.
This is a sample of code that I wrote that illustrates one of the two dilemmas I am having.
This error passes the error (back-space and all) and then gets an error when the function attempts to convert the string number to integer. My main objective here is to get rid of all these \x08 from the backspaces.
The second error results when I back-space after initially giving bad input. After giving bad input and back-spacing, the program gives the error message in line 12, instead of the expected one in line 13.
I honestly do not know enough about coding to know why this happens, so please forgive the lack of effort on my part.
This is a sample of code that I wrote that illustrates one of the two dilemmas I am having.
Sample code that produces erroneous input:
from inquirer import errors, prompt, Text
def check_even(ans,cur):
if int(cur)%2!=0:
raise errors.ValidationError('',reason='The inputted integer is not even!')
return True
def is_this_even(hex10_error=True):
if hex10_error:
val=True
else:
val=check_even
question=[Text(
name='',
message='Please input some integer...',
validate=val
)]
return int(prompt(question)['']) % 2 == 0
if __name__=='__main__':
error=True
even=is_this_even(error)
print(even)
This error passes the error (back-space and all) and then gets an error when the function attempts to convert the string number to integer. My main objective here is to get rid of all these \x08 from the backspaces.
Error 1: Hexadecimal str recorded, not literal string:
[?] Please input some integer...: 4564
Traceback (most recent call last):
File "C:/Users/Eclair/Documents/3 Projects/Project Aenir/test.py", line 17, in <module>
even=is_this_even()
File "C:/Users/Eclair/Documents/3 Projects/Project Aenir/test.py", line 14, in is_this_even
return int(prompt(question)['']) % 2 == 0
ValueError: invalid literal for int() with base 10: '4564\x08\x08\x08\x08\x08'
The second error results when I back-space after initially giving bad input. After giving bad input and back-spacing, the program gives the error message in line 12, instead of the expected one in line 13.
Error 2: Back-spacing after giving bad input.:
[?] Please input some integer...: 4545
>> "454" is not a valid .
>> The inputted integer is not even!
I honestly do not know enough about coding to know why this happens, so please forgive the lack of effort on my part.