0

but does anyone know how to make an input work as such, for example I am making a chatbot with this pyscript method and I have this simple problem, I cannot make the entered text be saved in the variable to do this process, I am new to this and it would help me, here in the python code fragment you can see a def with the name get_response(user_input) that method is the one that is in charge of generating everything but it gives me an error when executing it since the "user_input" does not has no data entered is the only error I have and I don't know how to fix it so I can read it in html

def get_response(user_input):
split_message = re.split(r'\s|[,:;.?!-_]\s*', user_input.lower())
response = check_all_messages(split_message)
return response
  • Simply your question is: How can you handle the errors when the function `get_response()` executing without data in `user_input`?. In this case, you always have to give `get_response(--data--)` function some data in order to execute it, even with using empty string `" "`. You would create the condition to check user input and if it is null or empty, just simply give it an empty string `get_response(" ")` – DrakeLiam May 11 '22 at 23:00
  • Where is **user_input** coming from? As written your question is incomplete. Post a complete example. https://stackoverflow.com/help/minimal-reproducible-example – John Hanley May 11 '22 at 23:21

1 Answers1

0

It has document element selectors, you can normally use an input(text).

Use the following as:

<input type=“text” id=“my-txt-field” />
.
.
.
user_input = Element('my-txt-field').element.value;
print(user_input)
Trishant Pahwa
  • 2,559
  • 2
  • 14
  • 31
  • It didn't work for me, it keeps giving an error, I don't know if I misplaced it in the code – Cremosidad May 11 '22 at 23:44
  • I hope this helps: https://stackoverflow.com/a/72093922/6072570 – Trishant Pahwa May 11 '22 at 23:48
  • I had already seen it and I have already managed to make it do that but it only prints the value again but does not perform the other actions what I am looking for as a reference is, for example, a sum of 2 numbers where I write them on the web page and with 1 button do the calculation using pyscript – Cremosidad May 11 '22 at 23:54