0

I have a python script containing a function to sum of two number.I want to create a logfile which logs everything during execution.How should I do that?Could you please explain with some example?

def sum(a,b):
    retrun a + b

a = sum(10,20)
khelwood
  • 55,782
  • 14
  • 81
  • 108
alok kumar
  • 67
  • 1
  • 5

1 Answers1

1

You can create a simple log file by,

  1. Opening a file at a known location with proper access mode e.g. filehandle = open(Logfilefullpath, "a+") - Opening in append mode.
  2. Use the write function to log your required information to the file. e.g. filehandle.write("sum function... ")
  3. Close the filehandle to release the file. e.g. filehandle.close()
Karthi
  • 11
  • 2