Python Forum

Full Version: Getting Shell to take prompt string plus int value and carriage return
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
#
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.