Python Forum
Getting Shell to take prompt string plus int value and carriage return
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting Shell to take prompt string plus int value and carriage return
#1
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
#
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  i see no prompt in the shell ? trix 5 526 Nov-09-2023, 09:23 PM
Last Post: trix
  Regular expression: return string, not list Pavel_47 3 2,452 Jan-14-2021, 11:49 AM
Last Post: Pavel_47
  return string from function with one argument jamie_01 2 2,145 May-28-2020, 11:07 PM
Last Post: menator01
  [split] script: remove all "carriage return" from my json variable pete 2 2,744 May-05-2020, 03:22 PM
Last Post: deanhystad
  How to Save Full Email Body to CLOB in Oracle w/Carriage Returns? bmccollum 1 2,234 Mar-12-2020, 10:25 PM
Last Post: Larz60+
  script: remove all "carriage return" from my json variable mfran2002 4 11,088 Feb-20-2019, 05:07 AM
Last Post: mfran2002
  How to return a standard output instead of string kavindu 1 2,490 Oct-28-2018, 01:09 PM
Last Post: ichabod801
  Return string from Javascript ian 0 2,256 Feb-11-2018, 04:41 PM
Last Post: ian
  Inserting carriage return to string. rhubarbpieguy 1 3,489 Mar-09-2017, 09:47 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020