pycharm mac reconstruction Tutorial

PyCharm is a powerful Python editor with cross-platform, for some pycharm pro senior staff, how to reconstruct pycharm 2019 mac?

01114220_05a7216695.jpeg

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:

01113800_0a132fa197.jpeg

2. Simplified rational
Let's simplify the rational number by dividing the greatest common divisor of the numerator and denominator:

01113812_c65a4588b5.jpeg

3. Extraction
Now, let's search for the greatest common divisor extracted into a separate method. To do this, select statement

01113836_c5676ac0bb.jpeg

And press Ctrl + Alt + M . Type the name of the method (gcd) in the dialog box that opens, and click "  OK ":

01113846_c9bedf264d.jpeg

4.内联局部变量并更改方法签名
让我们factor通过使用内联变量 重构来摆脱变量。为此,请将插入符号放在有问题的变量上,然后按Ctrl+Alt+N。所有检测到的factor变量都是内联的。
接下来,使用Change signature更改参数名称。为此,请将插入符号放在方法声明行中,然后按Ctrl+F6。在 对话框打开,重命名参数denom,并numxy分别,并单击图标节点upLevel()更改参数的顺序。
您最终得到以下代码:

01113910_3e63c12d65.jpeg

5.使用快速修复
现在,让我们将现有的静态方法转换为函数。要执行此操作,请按 Alt+Enter建议列表中的选择 将静态方法转换为功能,然后按Enter01113918_f7739c74ec.jpeg

6.将函数移动到另一个文件
现在,我们将把函数移动到一个单独的文件并添加一个import语句。为此,请将插入符号放在函数gcd声明中,然后按F6。在打开的 对话框中,指定目标文件的完全限定路径util.py。此文件不存在,但会自动创建:01113927_200780e5f6.jpeg

import语句也会自动添加。因此该文件rational.py如下所示:

01113952_ba69a53312.jpeg

7.进一步改变Rational类
添加魔术方法
接下来,让我们为类的对象添加加法/减法操作的魔术方法的声明Rational

01114059_940b723658.jpeg

提取方法并使用快速修复
接下来,我们将表达式提取Rational(other, 1)到一个单独的方法中。为此,请将插入符号放在上述表达式中,按,然后Ctrl+Alt+M在打开的 对话框中键入新方法名称 from_int
最后,将插入符号放在方法from_int声明中,按 Alt+Enter,从建议列表中选择Make method static,然后按Enter01114113_0aece7d09a.jpeg

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:

01114131_7bffb131e0.jpeg01114137_dc052eba53.jpeg

Guess you like

Origin blog.51cto.com/14370425/2420721