Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm debugging from saved state

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

like image 523
Omer Avatar asked Apr 11 '16 08:04

Omer


People also ask

How do I enable debugging in PyCharm?

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.

Can you step through code in PyCharm?

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


1 Answers

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.

  • Example Code
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.

like image 99
squeezer44 Avatar answered Sep 20 '22 20:09

squeezer44