Python Forum
Getting Shell to take prompt string plus int value and carriage return - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Getting Shell to take prompt string plus int value and carriage return (/thread-29359.html)



Getting Shell to take prompt string plus int value and carriage return - bayouprophet - Aug-29-2020

I am using the following to validate credit cards. I want my script to access the shell inputting a string, plus the card number and carriage return.

card_number = list(input("Please enter a card number: ").strip())
What I am asking is can I put the actual cc# i.e. 5555555555555555 after Please enter a card number: and then have the shell do an Enter from my script instead of manual entry
#


RE: Getting Shell to take prompt string plus int value and carriage return - bowlofred - Aug-29-2020

I think what you're asking is to read the information one character at a time and assemble the string yourself.

It's a bit more work because input() knows to stop and hand you the whole thing when it gets the enter key. Here you have to pull in each character and decide when you're done. It also means that if the entering person types a mistake, you'll get the mistake first, then you'll probably get a backspace key and will have to decide how to "fix" it.

But if you want to try that there's readchar. I haven't used it myself, but should be a good starting point.

The shell isn't involved here. It's not processing the input, and it certainly doesn't know when you're done and it's the right time to send an enter.