0

I am using VS Code for Python development.

BranchList=['BD','WE','BB','GB','MB']
if lastMonth[-2:]=='01':
    month='Jan'
elif lastMonth[-2:]=='02':
    month='Feb'
elif lastMonth[-2:]=='03':
    month='Mar'
elif lastMonth[-2:]=='04':
    month='Apr'
........

If I want to use 'try: except' to catch the exception(add a try: before the 1st row), all the rows below the 'try: ' should have additional 4 spaces indent. It's a very big manual work to add the 4 spaces indent for every rows. Is there any quick way to do it in VS Code?

hc_dev
  • 8,389
  • 1
  • 26
  • 38
ice7101
  • 69
  • 5
  • 2
    By the way, `datetime` module already has functions to convert month integers into short strings – OneCricketeer Jan 10 '22 at 21:11
  • More specific QA to [`indentation in VS Code for Python`, incl. recommended extensions](https://stackoverflow.com/questions/37143985/visual-studio-code-indentation-for-python/46899704#46899704) . – hc_dev Jan 10 '22 at 21:28

1 Answers1

1

If you highlight all the rows and press Tab, they should all indent. Shift+Tab will deindent.

  • Using __press Tab to indent__ selection (or deindent with Shift+Tab) is a common keyboard-shortcut in many editors. Equally common would be __holding Shift__ and use cursor-keys (up/down/left/right) to select text or entire lines. – hc_dev Jan 10 '22 at 21:24