Run a loop until it gets an error then run something else

im using config parser to read an ini file for links then put those links into an array for later use i tried using the try function but i cant seem to get it working

i feel its a simple solution and i just cant see it

config_read = configparser.ConfigParser()
config_read.read("default.ini")

current = 0
all_links = []
while True:
	try:
		current = current + 1
		tst =  "link"+ str(current)
		link = config_read.get("links",tst )

		time.sleep(0.25)
		all_links.append(link)
		print(link)
	except:
		pass
		
print(all_links)

edit:
heres the ini file too

[links]
link1=1
link2=2
link3=3
link4=4
link5=5

Have you tried break instead of pass? That should break the while loop.

yeah its working now i did try break earlier but it didnt work must’ve been something i changed

thanks for the help!

1 Like