Python Forum
check if input is correct before proceeding
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
check if input is correct before proceeding
#1
I need to enter the path to the files I want to manipulate, by name pathToExcel, pathToPhotos. A few times I got it wrong and the program did not run. I had to start again.

What I would like is a little loop that prints the input, asks if it is correct, then proceeds. If the input is wrong, it should ask for new input.

I'm thinking along the lines of:

while True:
	print('enter the path to the excel file or enter nothing to stop): ')
	path = input()
	print('Is this path correct? ' + path)
but what should I put next? What is the best way to do this?
Reply
#2
The thing to do (IMO) is to check the path entered for validity, to see if the file exists. If not, then you can loop back and ask for another try.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 421 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  I want to check if the input is str or is int & if it's str repeat the loop HLD202 4 2,804 Nov-23-2020, 11:01 PM
Last Post: perfringo
  Check all input, easy way! Help pls! bntayfur 2 1,810 Jul-05-2020, 10:58 PM
Last Post: bntayfur
  input check help! bntayfur 3 2,368 Jun-02-2020, 11:38 PM
Last Post: bowlofred
  Python - Most effective way to correct keyboard-user-input. ppel123 8 4,181 Apr-08-2020, 07:41 AM
Last Post: ppel123
  How to continue in loop until correct input received sunnyarora 10 9,955 May-04-2019, 02:37 PM
Last Post: Yoriz
  how i can check the input type? Firdaos 3 2,867 Dec-13-2018, 11:39 PM
Last Post: wavic
  Validating Input (basic check for int etc) gruntfutuk 1 2,491 Aug-06-2018, 07:43 AM
Last Post: gruntfutuk
  Check to see if file is submitted in correct folder DBS 9 8,144 Oct-21-2016, 07:06 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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