It sounds from your question like you have some lines at the beginning of a script which you do not want to process each time you run the script. That particular scenario is not really something that makes a lot of sense from a scripting point of view. Scripts are read from the top down unless you call a function or something. With that said, here is what I’m gathering you want your workflow to be like:
- Do some time consuming data loading (once)
- Try out code variations until one works
- Be able to run the entire thing when you’re done
If that’s accurate, I suggest 3 options:
- If you don’t need the data that’s loaded from step 1 in the specific code you’re testing, just comment out the time consuming portion until you’re done with the new code
-
If you do need the data, but not ALL of the data to test your new code, create a variable that looks like a small subset of the actual data returned, comment out the time consuming portion, then switch it back when complete. Something like this:
# data_result = time_consuming_file_parser() data_result = [row1, row2, row3] # new code using data_result
-
Finally, if you absolutely need the full data set but don’t want to wait for it to load every time before you make changes, try looking into
pdb
or Python DeBugger. This will let you put a breakpoint after your data load and then play around in the python shell until you are satisfied with your result.import pdb pdb.set_trace()
1
solved Run python code from a certain point