Posts

Showing posts from February, 2022

Python concepts

 Read and write to the ini file: ontents in my  backup_settings.ini  file [Settings] year = 2020 python code for reading import configparser config = configparser.ConfigParser() config.read( 'backup_settings.ini' ) #path of your .ini file year = config.get( "Settings" , "year" ) print (year) for writing or updating from pathlib import Path import configparser myfile = Path( 'backup_settings.ini' ) #Path of your .ini file config.read(myfile) config. set ( 'Settings' , 'year' , '2050' ) #Updating existing entry config. set ( 'Settings' , 'day' , 'sunday' ) #Writing new entry config.write(myfile. open ( "w" )) output [Settings] year = 2050 day = sunday 2. Glob module: blog 3. Pathlib module: blog 4. read and writoing contentsto ini file(2 ways using modules): i)config parser( here or here )(basic) ii)config updater( here )(advanced) ocnfig updater package: here

Adv concepts in Python

 1.Logging  Basic logging basicConfig Creating Logger object Using external config, and using dictConfig and fileConfig() All logging concepts covered  here :  Basic and advanced github code More notes available on Durga advanced python nodes last pages Note: When creating a logger as shown below, it propagates its log messages to root logger, i.e if logger is defined inside a module, which is imported by other file in which logging is defined using basicConfig.All the messages of logger are propagated to logging, because  logging.getLogger(__name__), has 1 additional field  Propagate, whose default value is set to true.We need to explicitly set it to false to stop propagation logger = logging.getLogger(__name__)  2.Argparse Open in incognito, blog confusing store_true and store_false: blog