Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
condensing try except
#1
There must be a way to achieve this type of code. As it is its violating everything about DRY...


also is there any way to condense try except statements within 1 while True looks?
example

while True:
	try:
		foo = str(input('enter a string: '))
		bar = int(input('enter a bar num > '))
		moo = int(input('enter moo num > '))
		break
	except ValueError:
		if foo != str(foo):
			print('must be a word...')
		else:
			print('number please')
		continue
there must be a way to tighten this up...
Reply


Messages In This Thread
condensing try except - by mepyyeti - Jan-18-2018, 06:39 AM
RE: condensing try except - by metulburr - Jan-18-2018, 06:47 AM
RE: condensing try except - by Gribouillis - Jan-18-2018, 08:15 AM
RE: condensing try except - by mepyyeti - Jan-18-2018, 05:20 PM
RE: condensing try except - by Gribouillis - Jan-18-2018, 06:20 PM
RE: condensing try except - by mepyyeti - Jan-26-2018, 10:19 PM
RE: condensing try except - by Gribouillis - Jan-26-2018, 11:13 PM

Forum Jump:

User Panel Messages

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