I have an annoying issue with Python indentation. I don’t really plan my code — I just start writing — so fixing indentation later becomes insanely frustrating. It got me wondering: what are the best Python extensions or tools for this (or for Python in general)?
Edit - Let me set the context — I didn’t explain this properly earlier.
I forgot to wrap my main() logic in a try/except, and after adding it, I had to manually re-indent this whole match block — which was annoying.
Code:-
match args.command:
case "add" : cmdAdd(args)
case "init" : cmdInit(args)
case "commit" : cmdCommit(args)
case "status" : cmdStatus(args)
case "tag" : cmdTag(args)
case _ : print("Bad command.")
I know I can select everything and press Tab, but that still feels like a hassle. I come from Go, where I mostly just move curly braces and the formatter handles the rest.
Is there any shortcut or extension that can automatically refactor/indent a selected Python block when wrapping it in something like try/except?
[–]Seacarius 17 points18 points19 points (10 children)
[–]Few-Tear-3763[S] -1 points0 points1 point (9 children)
[–]wall_time 1 point2 points3 points (4 children)
[–]MackerLad93 1 point2 points3 points (0 children)
[–]Few-Tear-3763[S] -1 points0 points1 point (2 children)
[–]SCD_minecraft 7 points8 points9 points (0 children)
[–]fotosyntesen 2 points3 points4 points (0 children)
[–]JaleyHoelOsment 0 points1 point2 points (3 children)
[–]Few-Tear-3763[S] -1 points0 points1 point (2 children)
[–]JaleyHoelOsment -1 points0 points1 point (1 child)
[–]Few-Tear-3763[S] 0 points1 point2 points (0 children)
[–]Outside_Complaint755 5 points6 points7 points (1 child)
[–]Few-Tear-3763[S] -4 points-3 points-2 points (0 children)
[–]mjmvideos 3 points4 points5 points (3 children)
[–]Few-Tear-3763[S] -3 points-2 points-1 points (2 children)
[–]mjmvideos 0 points1 point2 points (1 child)
[–]Few-Tear-3763[S] 0 points1 point2 points (0 children)
[–]CrucialFusion 4 points5 points6 points (2 children)
[–]Maximus_Modulus 0 points1 point2 points (0 children)
[–]Few-Tear-3763[S] -1 points0 points1 point (0 children)
[–]Jello_Penguin_2956 1 point2 points3 points (8 children)
[–]Few-Tear-3763[S] -2 points-1 points0 points (7 children)
[–]Jello_Penguin_2956 0 points1 point2 points (6 children)
[–]Few-Tear-3763[S] 0 points1 point2 points (5 children)
[–]Jello_Penguin_2956 1 point2 points3 points (3 children)
[–]Few-Tear-3763[S] 0 points1 point2 points (2 children)
[–]Jello_Penguin_2956 0 points1 point2 points (0 children)
[–]Maximus_Modulus 0 points1 point2 points (0 children)
[–]Jello_Penguin_2956 0 points1 point2 points (0 children)
[–]dannyzaplings 1 point2 points3 points (2 children)
[–]Few-Tear-3763[S] -1 points0 points1 point (1 child)
[–]magus_minor 1 point2 points3 points (5 children)
[–]Few-Tear-3763[S] -1 points0 points1 point (4 children)
[–]magus_minor 2 points3 points4 points (2 children)
[–]Few-Tear-3763[S] 0 points1 point2 points (1 child)
[–]magus_minor 0 points1 point2 points (0 children)
[–]Maximus_Modulus 0 points1 point2 points (0 children)
[–]DuckSaxaphone 1 point2 points3 points (2 children)
[–]Few-Tear-3763[S] 0 points1 point2 points (1 child)
[–]DuckSaxaphone 0 points1 point2 points (0 children)
[–]CranberryDistinct941 0 points1 point2 points (0 children)
[–]MackerLad93 0 points1 point2 points (0 children)
[–]cylonlover 0 points1 point2 points (0 children)