Nov-08-2022, 07:18 PM
Hi Team,
I am new in python, used functional programming, not perfect in oop concept yet.
In below task I have used try except block for handling error.
Can we reduce code, multiple try except block in my code.
what is the best way of doing it. thanks.
I have 10 python modules\files of a project.
Created a function in each module
imported all functions in main module.
calling all functions sequentially
I am try except block
I am new in python, used functional programming, not perfect in oop concept yet.
In below task I have used try except block for handling error.
Can we reduce code, multiple try except block in my code.
what is the best way of doing it. thanks.
I have 10 python modules\files of a project.
Created a function in each module
imported all functions in main module.
calling all functions sequentially
I am try except block
from project_connectsql import connectsql from project_stored_procedure import stored_procedure from project_update_Control_Table import update_Control_Table from project_extract_dynamic_header_name import extract_dynamic_header_name from project_extract_sql_Records import extract_sql_Records from project_write_Data_csv import write_Data_csv from project_create_gzip import create_gzip from project_backup import backup from project_cloud_move import cloud_move from project_Delete_files import Delete_files from Readtime import Readtime import os import sys import traceback def main() try: validate(input1,input2) except Exception as e: print("error occured while validating input value") try: connectsql(server,database) except Exception as e: print("error occured") sys.exit() try: stored_procedure(server,database,table) except Exception as e: print("Error occured at stored procedure") sys.exit() try: stored_procedure(server,database,table) except Exception as e: print("Error occured at stored procedure") logger.info("Error occured while connecting stored procedure") sys.exit() try: update_Control_Table(server,database,table,fnmae,status=1) except Exception as e: print("Error occured while updating updating control table in sql") logger.info("Error occured while updating updating control table in sql") sys.exit() try: extract_dynamic_header_name(server,database,table) except Exception as e: print("Error occured while while extracting file name convention") logger.info("Error occured while updating updating control table in sql") sys.exit() try: extract_sql_Records(server,database,table) except Exception as e: print("Error occured while extracting sql recordsl") logger.info("Error occured while extracting sql recordsl") sys.exit() try: write_Data_csv(folderpath,fname) except Exception as e: print("Error occured while while writing it data into csv") logger.info("Error occured while extracting sql recordsl") sys.exit() try: generate_chksum(folderpath,fname) except Exception as e: print("Error occured while while generating checksum no") logger.info("Error occured while extracting sql recordsl") sys.exit() try: create_gzip(folderpath,fname) except Exception as e: print("Error occured while while generating gzip file") logger.info("Error occured while generating gzip file") sys.exit() try: backup(sourcepath,destinationpath) except Exception as e: print("Error occured while taking backup") logger.info("Error occured while taking backup") sys.exit() try: cloud_move(mainfolderpath) except Exception as e: print("Error occured while moving files to cloud") logger.info("Error occured while moving files to cloud") sys.exit() try: Delete_files(mainfolderpath) except Exception as e: print("Error occured while archiving") logger.info("Error occured while archiving") sys.exit() if __name__"__main__": main()