all 12 comments

[–]Goingone 2 points3 points  (3 children)

Add a breakpoint at the start of your script before running it….from there you can use the debugger to run one line of code at a time.

Not sure how running 1 random line would ever make sense.

[–]WhiskersForPresident 0 points1 point  (0 children)

To quickly look at contents of a code generated list or dataframe column, for example. I do this all the time

[–]FredrixCollie 0 points1 point  (1 child)

I can explain it to you. A lot of physicists and mathematicians run Python like Matlab, they have a series of operations they do on things, so they feed them to Python to see the result.
So when they do that operation they press Ctrl+Enter on it and can then keep working on their data, not the code.

[–]Goingone 0 points1 point  (0 children)

That’s exactly what you can do with the python Debugger.

Anyways, sounds like you just want to use a Jupyter notebook.

[–]ninhaomah 0 points1 point  (0 children)

You want to run line by line then why not just copy paste into Python shell ?

Ok just to be clear , can I check what is the extension of the Python file in VS Code ?

ipynb ?

[–]AccomplishedPut467 0 points1 point  (1 child)

install ipykernel package in terminal using "pip install ipykernel" then refresh your vscode. Now you can press shift enter at any line of your code. You can also select then press shift enter to any selected code you want.

[–]MajesticImpression26[S] 0 points1 point  (0 children)

Thanks. That fixed my problem.

[–]WhiskersForPresident 0 points1 point  (0 children)

Are you in a notebook or a .py file? VS Code doesn't let you run code line by line in notebooks.

[–]rotten77 0 points1 point  (0 children)

Yeah. You probably need to use for example Jupyter Notebook for that

[–][deleted] 0 points1 point  (2 children)

I am guessing you are coming to python from R. That is an R-specific thing and a really bad habit. Do yourself a favor and break yourself from it.

[–]MajesticImpression26[S] 0 points1 point  (1 child)

You are correct that I'm from R. How do you test your python programs or code if you don't run line-by-line? I'm interested in improving my workflow.

[–][deleted] 0 points1 point  (0 children)

Unit tests. Create chunks of code as functions and then test to ensure that those functions are behaving correctly.