I am learning flask and building a app based on Corey Schafer's Youtube tutorials. I'm using VS-Code as my editor of choice.
In tutorial 5 he splits his app into a package structure and when I do it I run into a problem. In my settings I enabled the "editor.formatOnSave": true
and the formatter I use is autopep8.
Now when I move one of my import statements from the top to the bottom of my file and save, the formatter moves it back to the top. I'm guessing its because of 'E402 - Fix module level import not at top of file'?
I tried to ignore it with the "python.formatting.autopep8Args": [--ignore=E402]
but that did nothing. Maybe here you can only turn of lynting errors and E402 is only a lynting error and its not relevant for the formatting?
I hope you can help me disable or fix it.
Cheers
You have configured prettier to format as per the default settings. If you don't see the code formatted automatically on file save then it might be because you have multiple formatters installed in VS Code.
Click the “Settings” gear icon in the bottom-left corner. Search “Formatter” and click the “Editor: Default Formatter” option. From the drop-down menu, select whichever code formatter you want to use. Scroll down a bit and check the box next to the “Editor: Format On Save” option.
In VSCode, go to File -> Preferences -> Settings and click on the icon in the top right hand corner to open up the settings in JSON. Et voilà! Your imports will now be organized every time you save a file.
Brett Cannon comment:
I don't know autopep8 well, but that example is mis-formatted as you're missing quotes around the argument:
"python.formatting.autopep8Args": ["--ignore=E402"]
@BrettCannon terrific! That fixed it. Tried so long to fix it that i forgot those quotes and didnt see that they were missing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With