Category : try-catch

I wrote code to connect to MySQL, and if I connect successfully it works well like the following: from mysql import connector try: conn = connector.connect(host="localhost", database="world", user="root", password="rightPWD") print(conn.is_connected()) except connector.Error as err: print(err) finally: conn.close() But if I intentionally use the wrong password: try: conn = connector.connect(host="localhost", database="world", user="root", password="wrongPWD") print(conn.is_connected()) except connector.Error ..

Read more

I need some help. I need my code to continue the "for" after error, just show the ticket with an error and skip to the next one without stopping the script. from zenpy.lib.api_objects import CustomField from zenpy import Zenpy import csv, sys creds = { ’email’ : ‘xxxxxxxxxxx’, ‘token’ : ‘xxxxxxxxxxx’, ‘subdomain’: ‘xxxxxxxxxxx’ } zenpy_client ..

Read more

What is the difference between these two approaches – Aproach 1 try: statement_1 except: what_to_do_if_statement_1_errs else: what_to_do_after_statement_1_runs finally: whatever_happens_with_statement_1_run_this Approach_2 try: statement_1 except: what_to_do_if_statement_1_errs else: what_to_do_after_statement_1_runs whatever_happens_with_statement_1_run_this Source: Python..

Read more

import math def coprimeTestFunction(val1, val2): if val1 < 0 or val2 < 0: raise ValueError if type(val1) != int or type(val2) != int: raise ValueError result = math.gcd(val1, val2) if result == 1: print(‘The values {0} and {1} are coprime’.format(int1, int2)) elif result != 1: print(‘The values {0} and {1} are not coprime, they have ..

Read more

I want to do very simple thing – I want to create a loop that will not end when error will occur. We call know that function that we need is try, however I’m dealing some problem with this implementation. I tried try: for i in range(1, 100): raise ValueError(‘A very specific bad thing happened.’) ..

Read more

This is part of satelite data processing modules currently running on Linux server. The codes are complete mess. Hardly any footnotes, docstrings, or try~except. Our objectives are more objectified modules, more docstrings, footnotes and try-except parts. Can you please please check if any functions in aux_ssmi.py can be switched to methods? and among other py ..

Read more