PyCharm Flashcards
Effective PyCharm 9 topics
- Projects
- Editor
- Git
- Refactoring
- Databases
- Debugging
- Profiling
- Testing
- Packaging
Projects: 4 kinds of roots
- Source roots: for resolving imports
- Resource roots: images, style sheets
- Excluded: ignored by PyCharm
- Template folder: templates
Projects: Add installed package to requirements.txt
Right click on the import > Add imported packages to requirements.txt
Projects: search everywhere
Double Shift:
1. Search classes
2. IDE actions
3. files
4. Git
Projects: search show_leaderboard()
Double shift > s_l
Editor: create a function in module by simply calling the function
alt+enter
mymodule.new_func() # Create function new_func() in module mymodule.py
Editor: install a package by simply calling the package’s function
resp = requests.get(url) # alt+enter # 'Install and import package 'requests'
Editor > Live Templates
main
turns into ‘if __name__ == ‘__main__’
Search settings for ‘Live Templates’ to edit templates
Hot key for arguments tooltip
Ctrl + P
Turn regular string into f-string
print('{e') # autocompletion pop-up with available variables
To enhance autocomplete…
provide type hints
~~~
def my_func(arg) -> Optional[User]
~~~
How to discover new features?
Open action palette and search for stuff:
~~~
Ctrl + Shift + A
~~~
Find usages
F7
Pre-commit settings
You can optimize imports and reformat the code in the commit window
Select only certain changes for a commit
In the git palette on the left click ‘diff’ icon and press checkmarks next to the changes you want to include
Create label in local history
Right click - Local history - Put label…
‘Refactor this’ hotkey
Ctrl + Alt + Shift + T
^ T (Mac)
5 Main Refactor tools
1. Extract/introduce Variable/Constant/Parameter Object/Method/Field/Superclass 2. Inline is the opposite of extract/introduce 3. Pull class members up/down 4. Move (a class) to another file (or drag and drop them) 5. Move to a package
Visualize only specific tables
Select tables and click visualization
Debug: conditional breakpoint
Add Condition checkmark
or click More on the breakpoint pop-up
Profiling the app
Click Profile icon (3rd from the Run)
Enable custom config .ideavimrc
Click on the IdeaVim icon > Enable .ideavimrc
My Custom IdeaVim enable/disable hotkey
Alt+v
Settings > Keymap > search ‘vim’ > Tools - Alt+v
My Custom VCS Next/Previous Change
Alt + PgUp
Alt + PgDn
My Custom Git Blame hotkey
CTRL+SHIFT+ALT+A
Show autocomplete
CTRL+Space
Add annotations
ALT+Enter
Choose annotation
Change selection CASE
Select
Shift x2
type ‘case’
PyCharm Actions
CTRL+SHIFT+A
(show line numbers)
Select a word or a keyword (if)
CTRL+W
Select the whole string or the whole keyword statement (if)
CTRL+W+W
Select the whole string with quote marks
CTR+W+W+W
Select the whole call within brackets
CTR+W+W+W+W
Shrink the selection
CTRL+SHIFT+W
Move line down
Action Palette: CTRL+SHIFT+A
Move Line Down (mld)