简体   繁体   中英

Why no need to load Python formatter (black) and linter (pylint) and vs code?

I am learning how to use VS code and in the process, I learnt about linting and formatting with "pylint" and "black" respectively.

Importantly, I have Anaconda installed as I often use conda environments for my different projects. I have therefore installed "pylint" and "black" into my conda environment.

My questions are as follows:

  • If "pylint" and "black" are Python packages, why do they not need to be imported into your script when you use them? (ie "import pylint" and "import black" at the top of a Python script you want to run). I am very new to VS code, linting and formatting so maybe I'm missing something obvious but how does VS code know what to do when I select "Run Linting" or "Format document" in the command palette? Or is this nothing to do with VS code ?

I guess I am just suprised at the fact we don't need to import these packages to use them. In contrast you would always be using import for other packages (sys, os, or any other).

  • I'm assuming if I used a different conda environment, I then need to install pylint and black again in it right?
  1. Yes, black and pylint are only available in the conda environment you installed them in. You can find them in the "Scripts"-folder of your environment.
  2. VS Code knows where to look for those scripts, I guess you can set which package is used for "Run Linting" or "Format document".
  3. You only need to import python modules or functions that you want to use inside your python module. But that's not what you do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM