1

I was following this beginner tutorial. I'd like to use a formatter to adjust indentation as he did. I tried to do the same things he did but it doesn't work.

How can achieve the same result?

4
  • Not many people will want to watch a video. You could just post screenshots of before and after Commented Nov 24, 2023 at 5:21
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Nov 24, 2023 at 5:21
  • The linked video does talk about indentation but does not show any formatter at least not at the linked point of the video.
    – Robert
    Commented Nov 24, 2023 at 15:28
  • 1
    @Robert it talks about it in the subsequent 30 seconds: youtu.be/qwAFL1597eM?feature=shared&t=1488
    – KaMZaTa
    Commented Nov 24, 2023 at 16:25

1 Answer 1

1

There are 2 ways to go about it.

Use Python Indent extension

This extension is required as an addition to main Python extension as that by default doesn't handle whitespaces for some reason. It's pretty much the most basic support.

Use an autoformatter

Then you have options for more advanced autoformatting like:

They're slower as they do much more, but if you want to efficiently and understandably program in Python, you'll have to get familiar with one at some point. Ruff is more recommended nowadays as it has more capabilities and it's written in Rust, so it's faster.

You can also run both Python Indent and autoformatter on file save, if you don't want to autoformat too frequently, which I'd definitely recommend as the way to go.

7
  • Thanks but this doesn't work. Python Indent extension partially cover the behavior shown in the video but (e.g.) doesn't fix the indent for line04 variable. I tried both Ruff and Black but nothing's changed when I try to format the document.
    – KaMZaTa
    Commented Nov 24, 2023 at 16:19
  • Did you follow install instructions for both accurately? E.g. did you set Ruff/Black as default Python formatters? Hard to say anything without seeing your exact config, but that's out of scope for software recommendations.
    – Destroy666
    Commented Nov 24, 2023 at 20:24
  • Yes, I think so. That's exactly the point: I originally asked on Stack Overflow ( stackoverflow.com/questions/77532112/… ) how to make Black works since it doesn't. Then users told me to change the original question to something like this. Then another user told me I cannot ask for recommendations on Stack Overflow and ask for them here. Now, are you asking me to post again how to make Black works on Stack Overflow?
    – KaMZaTa
    Commented Nov 25, 2023 at 1:24
  • However, do you confirm Black works for you with this same code? Has the line04 been indented? I'm using a brand new VSCode profile.
    – KaMZaTa
    Commented Nov 25, 2023 at 1:27
  • No, I have not tested with that scenario as it's completely unrealistic to occur under normal circumstances, as Python Indent will just automatically insert correct indentation for new lines. Perhaps you need to be more accurate as to what your exact problem is and what you want to achieve. Fix random completely incorrectly indented files? Or maybe you have a habit of pressing whitespaces from other language? I have no idea. Since following a video and an example that will never happen normally for most devs is not a real use case.
    – Destroy666
    Commented Nov 25, 2023 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.