To make code convient and readable form it is neccessary to break code in multiple files, where you can write your code and write function can be later call on any where in the project. In python its easy to do.
Below is the sample code, i am taking the example from my previous post
py0012 : try catch in Python/ DB connection in try catch
which is having file name "file1" and t funcation made which will return something on db connection pass or fail and that can be used in mail file as per below code example. First we need to import file, then use funcation name directly "t()" without any file reference.
from file1 import *
if t() == "DBConnectionError":
# your code will stop here, dependent file will not throw any error
exit(0)
if t() == 1:
# if database connection pass it will move further as per the written commands, this also show that how we can handle error on other files call
driver = selenium.webdriver.Firefox(executable_path=FirefoxDriver, firefox_binary=binary, firefox_profile=profile)
Below is the sample code, i am taking the example from my previous post
py0012 : try catch in Python/ DB connection in try catch
which is having file name "file1" and t funcation made which will return something on db connection pass or fail and that can be used in mail file as per below code example. First we need to import file, then use funcation name directly "t()" without any file reference.
from file1 import *
if t() == "DBConnectionError":
# your code will stop here, dependent file will not throw any error
exit(0)
if t() == 1:
# if database connection pass it will move further as per the written commands, this also show that how we can handle error on other files call
driver = selenium.webdriver.Firefox(executable_path=FirefoxDriver, firefox_binary=binary, firefox_profile=profile)
No comments:
Post a Comment