Is there a way to debug a code in parts? Meaning, I wish to debug the code until a certain point, save the variables state and continue to debug from that point on. Thanks
Just right-click any line in the editor and select the Debug <filename> command from the context menu. After the program has been suspended, use the debugger to get the information about the state of the program and how it changes during running.
Step through the program Stepping is the process of controlling step-by-step execution of the program. PyCharm provides a set of stepping actions, which are used depending on your strategy (for example, whether you need to go directly to the next line or enter the methods invoked on your way there).
With its debug function, Pycharm offers a fantastic opportunity to see the properties of certain variables if the breakpoint has been set accordingly.
Apart from that, Python itself offers an amazing way to serialize and de-serialize object structures with its built-in feature pickle (Pickle documentation).
The pickle.dump(VARIABLE) command can be used to dump variables at a certain state into a file or to be printed.
Sometimes I'm using pickle f.e. to dump a response variable into a file for later being used.
import pickle
import requests
r = requests.get('https://www.strava.com/api/v3/athlete')
#
# with open('assets/requests_test.pickle', 'wb') as write:
# pickle.dump(r.json(), write)
With that you're able to open this file manually or load it with pickle.load (VARIABLE) later in your code to do something useful with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With