1. Import Module
We often inadvertently use some of the classes and modules that have not yet been imported in the programming process, in which case the pycharm will help us locate the module file and add it to the import list, which is known as the Auto-import module feature.
To study this feature, we borrowed the Solver class that we had written earlier and entered the following code:
When entering Math.sqrt (d), Pycharm will pop up a menu to prompt you to import the missing modules:
Press Alt+enter to take the suggestion from the shortcut menu, and the Import command is added to the Code section of the import module, and the input cursor remains in place, allowing us to continue typing without repositioning:
It is worth mentioning that if you currently have multiple optional import resources, Pycharm will give you a list of prompts to choose from:
2. Configure Import Assistant
Here is a small problem, if this window appears to make you very upset, do not worry, click on the lower right corner of the handsome guy can close it:
Click on that handsome guy Avatar will pop up a window, cancel the import popup check box, this time the automatic import function is canceled. Of course, the same action can be done on Auto-import page pages of the Configuration dialog box (settings→editor→auto-import):
Of course, if you want to turn off the import assistant, simply uncheck the option (Settings→editor→auto-import).
3. Fast Import
Don't panic when the import assistant is turned off. At this point Pycharm will not give a hint directly, but will mark the code location of the missing module with a wavy red line, with a red bulb on the left, click on the light bulb, or press the Alt+enter shortcut key:
In this example, we should choose to import the corresponding default library, the import is complete, the red wavy line disappears.
4. Optimization of Import Assistant
When you are perfecting your code, you will always stop using some of the import declarations (for example, the library for debugging your code, which no longer works after debugging is complete). However, these import declarations still exist in your project and you have to stop to search from scratch to find and delete these statement statements, which are inefficient and error-prone, and are likely to be deleted or omitted.
Pycharm can help us dispose of these redundant import declaration statements, the so-called Optimize Imports feature, which can help you delete redundant import declaration statements from your project at any time.
Notice that the redundant imports statements in the Pycharm editing environment are grayed out:
To remove these redundant statements, press Ctrl+alt+o (or choose the Code→optimize Imports menu command), pycharm A dialog box that prompts you to select the files that need to be cleaned (the current file or all the files in the current directory):
Click OK to complete the cleanup:
The most complete pycharm tutorial (--pycharm) Automatic Import module of the editor function