import logging
def process(i,j,k):
return i+j+k
def main():
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
fh = logging.FileHandler('18.1_logFile.txt')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
arr=[]
arr=map(int,"1 2 3".split())
#arr=map(int,raw_input().split())
logger.debug("Number of integers read= {0}".format(len(arr))) #Debug statement
logger.debug("i = {0}, j = {1}, k = {2}\n".format(arr[0],arr[1],arr[2])) #Debug statement
print("sum= %i\n"%process(arr[0],arr[1],arr[2]))
if __name__=='__main__':
main()
import logging,sys
def process(i1,i2):
global logger
logger.debug("process (%i, %i)\n"%(i1, i2))
val=i1*i2
logger.debug("return %i\n"%(val))
return val
def main():
global logger
logging.basicConfig(filename='18.2_logFile.txt', filemode='w', level=logging.DEBUG)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
filemode = 'w'
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
fh = logging.FileHandler('18.2_logFile.txt')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
arg1=0
arg2=0
#Un-Comment this while executing from terminal/command line
#if(len(sys.argv)>1):
#arg1=int(sys.argv[1])
#if(len(sys.argv)==3):
#arg2=int(sys.argv[2])
#Dummy command-line-parameters
#execute as "python <filename>.py arg1 arg2" while executing from terminal and un/comment respective statements
a=['3','5']
logger.debug("processed %i arguments\n"%(len(a)))
#logger.debug("processed %i arguments\n"%(len(sys.argv)))
logger.debug("arg1 = %i, arg2 = %i\n"%(int(a[0]), int(a[1])))
print("product = %i\n" %( process (int(a[0]),int( a[1]))))
#logger.debug("arg1 = %i, arg2 = %i\n"%(arg1, arg2))
#print("product = %i\n" %( process (arg1, arg2)))
if __name__=='__main__':
main()
import logging,sys
def process(i1,i2):
global logger
logger.warning("process (%i, %i)\n"%(i1, i2))
val=i1*i2
logger.error("return %i\n"%(val))
return val
def main():
global logger
logging.basicConfig(filename='18.3_logFile.txt', filemode='w', level=logging.DEBUG)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
fh = logging.FileHandler('18.3_logFile.txt')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
arg1=0
arg2=0
#Un-Comment this while executing from terminal/command line
#if(len(sys.argv)>1):
#arg1=int(sys.argv[1])
#if(len(sys.argv)==3):
#arg2=int(sys.argv[2])
#Dummy command-line-parameters
#execute as "python <filename>.py arg1 arg2" while executing from terminal and un/comment respective statements
a=['3','5']
logger.debug("processed %i arguments\n"%(len(a)))
#logger.debug("processed %i arguments\n"%(len(sys.argv)))
logger.info("arg1 = %i, arg2 = %i\n"%(int(a[0]), int(a[1])))
print("product = %i\n" %( process (int(a[0]),int( a[1]))))
#logger.debug("arg1 = %i, arg2 = %i\n"%(arg1, arg2))
#print("product = %i\n" %( process (arg1, arg2)))
if __name__=='__main__':
main()
def main():
#Variable Declaration
sum=0
data = [1, 2, 3, 4, 5]
#Calculation
for i in range (0,5):
sum += data[i]
#Result
print("sum = %i\n"%(sum))
if __name__=='__main__':
main()
class date:
def __init__(self,m,d,y): #Class constructor
self.month=m
self.day=d
self.year=y
def foo(x):
x.day+=1
return x
def main():
#Variable Declaration
today=date(10,11,2004)
array=[1,2,3,4,5]
string="test string"
i=3
newdate=date(11,15,2004)
today=date.foo(today)
#Result
print("today= %d/%d/%d"%(today.day,today.month,today.year))
if __name__=='__main__':
main()