Here we will discuss how to use the common function print (or its equivalent in your programming language) to debug software that is not giving expected values or results, while also not having errors or warnings. We suggest three places to put print statements so you can debug your code.
Print to check key values
Print variable values at key steps in your code. This allows you to see if data has loaded or transformed correctly.
print( “var1 is “+ var1 + “at line 10”)
Print status messages
Print to log key steps in your process and demonstrate to yourself that certain files or objects have been created.
print( “successfully downloaded” + fileName)
print( “successfully parsed” + fileName)
Print to check code execution
Use print to check code execution. Since errors or warnings should stop parts of your code from running, this ensures you have reached those code sections. This is particularly useful if you have if/else logic or other logic that could cause parts of your code to not run if certain conditions are not met.
print( “Entered function foo”)
print( “Got past line 23”)
print( “Executing body of if statement”)
Quiz