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)
2

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.