logging - How to log errors before the try- except loop in python? -


i trying implement python's logging library log.

i understand if wrapped in try-catch loop, exception caught.

but in 1 of example, import failing start of script. not getting logged. ( printing in jupyter's logs)

how log these exceptions? looking not wrapping entire script in try - except loop.

any error on jupyter or ide printed in console, why not logger? isnt there such implementation

when using logger, have implement logging of errors.
in python, errors being logged console default.
so, if want use logger, have add logic catch , log errors.

the try except block common way handle import on python.

quoting dive python:

there lot of other uses exceptions besides handling actual error conditions. a common use in standard python library try import module, , check whether worked. importing module not exist raise importerror exception. can use define multiple levels of functionality based on modules available @ run-time, or support multiple platforms (where platform-specific code separated different modules).

the next example demonstrates how use exception support platform-specific functionality.

try:     import termios, termios                      except importerror:     try:         import msvcrt                                except importerror:         try:             easydialogs import askpassword          except importerror:             getpass = default_getpass                    else:                                                getpass = askpassword     else:         getpass = win_getpass else:     getpass = unix_getpass 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -