Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

87
Views
How to run multiline Python statement in VSCode without needing to select it all?

I want to be able to run the entirety of a multiline statement like this

dtypes = {
    'date' : 'str',
    'item_code' : 'category',
    'branch_code' : 'category',
    'sale_qty' : 'float',
    'sale_val' : 'float',
    'return_qty' : 'float',
    'return_val' : 'float'
}

by having the cursor on the first line and pressing a shortcut.

I currently have the command jupyter.execSelectionInteractive bound to ctrl+enter, however that only executes either the current line if nothing is selected or the selection. So in a statement like the one mentioned above, it would attempt to run dtypes = { only and fail with an error and I would need to manually select the whole statement to execute it.

This is a built in function in many IDEs like RStudio where if you press the shortcut for running the current line, it intelligently knows that the current line is part of a multiline statement and runs the whole statement.

I would like to know if there is a way to do this in VSCode?

I also already know that I can use the comment #%% to create Jupyter cells that I can run at once, but I don't want to have to insert #%% at every single multiline statement so I can execute it easily without selecting it all.

9 months ago ยท Santiago Trujillo
Answer question
Find remote jobs