PyCharm is a powerful Python editor with cross-platform, for some pycharm pro senior staff, how to reconstruct pycharm 2019 mac?
Before reconstruction pycharm pro 2019 mac, must first meet the following prerequisites:
You are using PyCharm version 2016.2 or later.
We have created a project.
Then proceed to step pycharm mac reconstruction:
1. Prepare an example (to create a project):
rational.py create a Python file in the project and add the following code:
2. Simplified rational
Let's simplify the rational number by dividing the greatest common divisor of the numerator and denominator:
3. Extraction
Now, let's search for the greatest common divisor extracted into a separate method. To do this, select statement
And press Ctrl + Alt + M . Type the name of the method (gcd) in the dialog box that opens, and click " OK ":
4.内联局部变量并更改方法签名
让我们factor通过使用内联变量 重构来摆脱变量。为此,请将插入符号放在有问题的变量上,然后按Ctrl+Alt+N。所有检测到的factor变量都是内联的。
接下来,使用Change signature更改参数名称。为此,请将插入符号放在方法声明行中,然后按Ctrl+F6。在 对话框打开,重命名参数denom,并num以x和y分别,并单击图标节点upLevel(↑)更改参数的顺序。
您最终得到以下代码:
5.使用快速修复
现在,让我们将现有的静态方法转换为函数。要执行此操作,请按 Alt+Enter建议列表中的选择 将静态方法转换为功能,然后按Enter:
6.将函数移动到另一个文件
现在,我们将把函数移动到一个单独的文件并添加一个import语句。为此,请将插入符号放在函数gcd声明中,然后按F6。在打开的 对话框中,指定目标文件的完全限定路径util.py。此文件不存在,但会自动创建:
import语句也会自动添加。因此该文件rational.py如下所示:
7.进一步改变Rational类
添加魔术方法
接下来,让我们为类的对象添加加法/减法操作的魔术方法的声明Rational:
提取方法并使用快速修复
接下来,我们将表达式提取Rational(other, 1)到一个单独的方法中。为此,请将插入符号放在上述表达式中,按,然后Ctrl+Alt+M在打开的 对话框中键入新方法名称 from_int。
最后,将插入符号放在方法from_int声明中,按 Alt+Enter,从建议列表中选择Make method static,然后按Enter:
Extract superclass
Next, we move to implement the method of __radd __, __ sub__ and move __rsub__ to the superclass. In addition, we will make the method __neg__ and __add__ summary.
That's the way it's done ...... caret in the class Rational statement, pointing to the context menu Refactor | extract and select superclass ...... Next, in the open dialog box , specify the superclass name (here AdditiveMixin ), and select the method to be added to the superclass. Method for __neg__ and __add__ , select Make abstract box column.
Finally get the following code: