Adding Fields In a Constructor

Let your IDE add constructor arguments to your instance.

The Problem

It's one of those chores...your class has an __init__ with some arguments, and you need to assign them to self. What a lot of typing.

The Solution

Let the IDE do it for you. As you type the argument name, press ⌥⏎ (macOS) / Alt+Enter (Windows/Linux) and choose Add 'field' to constructor.

add-field-constructor.png

PyCharm will create the assignment for you.


Related Resources

Navigation Bar - All the power!
Navigation Bar - All the power!
The Navigation Bar can do much more than you think!
Clean Up Messy Imports With Optimize Imports
Clean Up Messy Imports With Optimize Imports
Quickly remove any unused imports and more.
Find in Path with the Navigation Bar
Find in Path with the Navigation Bar
Use the Navigation bar and Find in File together and be faster than all of your team members.