python IDE's Pycharm novices get started Easy Tutorial

pycharm God is great I just started learning python process strongly recommend a highly efficient tool IDE, it's strong so you can not imagine! (Specifically, how strong I need to slowly groping) The following is from my django Chinese net --- PyCharm novice tutorial, just look at this is enough in the turn, I like this new to you certainly can understand Row

Currently pycharm There are two versions, Professional (Professional Edition) "and" Community Edition ", the most powerful professional version, primarily for Python and web developers prepared, is the need to pay. Community Edition is a Professional version of castration, relatively lightweight, primarily for Python and data experts prepared. And as our novice, with a community version can be enough!

I. Common Features

1, replacing the Python interpreter

If your system has multiple versions of python, you want to replace an interpreter, please use the following method:

Project Interpreter found at xxx: the File-> Setting-> Projec. Then you need to modify the Python interpreter. Note that this place must be noted that: in the choice of Python interpreter, be sure to choose to python.exe this file instead of python installation folder.

1.jpg

2. Create a new project

We create a new project, such as django.

2.jpg

1.jpg

3, adjust the editor font and font size and the size of its console

File--settings里

3.jpg

5.jpg

4, set the file encoding

File--settings里

4.jpg
5. Modify the document background color

File--settings里

6.jpg

6, so that a tab key instead of four spacebar

7.jpg

7, run Python code

在pycharm里面,我们不用借助windows下的cmd来运行程序了,pycharm直接提供了运行功能。在编写好程序之后我们有三种方法可以运行:
工具栏中的run,如果没有显示Toolbar,可以在view里面找到Toolbar并勾选。
在运行结果旁边也提供了run按钮。
直接单击鼠标右键然后单击run

8.jpg

8、设置模板

设置一个模板,里面可以放一些设置或者广告,下次新建的文件或模板时不用每次都输入

 
 

9.jpg

9、断点与调试

断点功能可以帮助我们调试代码。

设置断点:在代码前面与行号后面之间的空白处,鼠标单击,就可以设置断点。如下:

1.jpg

调试断点:

点击那个绿色的甲虫图标,进行断点调试。

2.jpg

启动之后,自动跳转到第一个断点。下方debugger里会显示该断点的信息。

 3.jpg

点击Step Over或者按F8,我们继续往下运行,到下一个断点,右边则显示当前行的信息!

二、常用高效pycharm使用方法

  • 定位

    • Search Everywhere

    • Ctrl+光标

    • 最近打开的文件

    • 目录树的“雷达”

    • 查找

  • 补全

    • Tab

    • 万能的Alt-Enter

    • Surroud with

    • Emmet

  • 编辑

    • Basic

    • Extend Selection/ Shrink Selection

    • 多光标

  • 重构

    • Rename

    • Safe delete

    • Extract

  • 调优

  • 颜值

  • 其它

定位

Search Everywhere

快捷键: double shift

可以搜文件名、目录名(后面加/)、类名、方法名、函数名。

Ctrl+光标

当按住ctrl,鼠标移到标识符上面时,会显示一些信息。

当按住ctrl,并点击时,可以跳到定义处

当在定义处按住ctrl,并点击时,会弹框列出所有引用的地方,只有一个地方引用时,会直接跳

最近打开的文件

ctrl-e

目录树的“雷达”

 20171202174346896.jpg

scroll from source.

目录树会定位到当前文件所在的位置。

查找

  • ctrl-f 当前文件查找

  • shift-cmd-f 全局查找

  • 目录树某个目录右键,Find in Path,可以只在这个目录范围内进行查找

补全

Tab

这个就不用说了。

万能的Alt-Enter

不同场景有不同的动作。比如当在一个未找到引用的变量按下alt-enter时,会弹窗,让你选择自动import、创建函数参数、重命名到一个已有的变量等。

Surroud with

快捷键: ctrl-alt-t

比如将光标所在的语句或块用try...except...包住。

Emmet

Emmet使用特定的语法来展开小段代码,它类似CSS选择器,使其成为完整的HTML代码。例如,下列序列:

div#page>div.logo+ul#navigation>li*5>a

将展开为:

<div id="page">

<div class="logo"></div>

<ul id="navigation">

<li><a href=""></a></li>

<li><a href=""></a></li>

<li><a href=""></a></li>

<li><a href=""></a></li>

<li><a href=""></a></li>

</ul>

</div>

编辑

Basic

  • ctrl-c(复制)。在没选择范围的情况下会复制当前行,而不需要先选择整行再复制。

  • ctrl-v(粘贴)。ctrl-shift-v可以在剪贴板历史中选择一个去粘贴。

  • ctrl-x(剪切)

  • ctrl-s(保存)

  • ctrl-z(撤销)。ctrl-shift-z反撤销。

  • ctrl-/(注释)。注释后光标会自动到下一行,方便注释多行。

  • ctrl-d(复制行)

  • ctrl-shift-u(转换大小写)

  • ctrl-alt-L(格式化)

  • ctrl-alt-o(优化import)

  • shift-alt-↑↓(上下移动行)、shift-ctrl-↑↓(上下移动语句。一个语句可能有多行。并且会决定要不要进块内和出块外)。简单的说,一个是物理移动行,一个是逻辑移动语句。

  • shift-enter(在下面新开一行)。ctrl-alt-enter在上面新开一行。

  • alt-←→单词级别的移动; ctrl-←→行首/行尾; shift-←→左右移动带选择; ctrl-[]块首/块尾; cmd+↑↓上一个方法/下一个方法。

  • cmd-L(Find/ Move to next Occurrence)

Extend Selection/ Shrink Selection

往外扩展选择范围。我一般用来选中单词、两个引号或括号之间的内容。而不是用鼠标费劲的去选。

多光标

  • Alt+点击(或拖动),在某个光标处再次点击,可以取消该光标。

  • 双击Alt不放,然后按↑或↓

  • cmd-g(Add Selection for Next Occurrence)

mmmm.gif

重构

Rename

比如将一个变量rename,所有用到这个变量的地方都自动跟着变。

Safe delete

比如删除一个文件,所有用到这个文件的地方也跟着删除。

Extract

提取选中的代码块生成一个新的变量、属性、方法、参数等

调优

  • Help->Edit Custom VM Options,配置多点内存,使流畅。

  • 禁用掉没用的插件。

颜值

装插件Material Theme UI。好看很多。

其它

  • 在配对符号'")]}的关闭符号前,按相同按键,会忽略并移动光标到后面,不用老远的去按→方向键。

  • Smart Keys(Preference->Editor->General->Smart Keys设置)

    • 输入单个时插入一对引号或括号

    • 当选中的时候输入引号或括号,在两边加上引号或括号,而不替换选择的内容

    • 换行时智能缩进

    • 在语句内换行时会自动拼上反斜杠/

    • 定义方法时自动插入self

    • “Reformat on paste” and “smart indent pasted lines”

  • 贤者模式(免打扰模式进行编码)

  • New Scratch File. 临时编辑文件时用

  • Copy Reference. 比如在某个函数右键Copy Reference,粘贴到django shell里面方便import。

  • Static analysis. For example, find duplicate code, the code checks whether the pep8 and so on.

  • New file in the directory tree, you can multi-layered, with even create directories. Mkdir -p of similar effect. For example, enter foo / bar / baz.py, if no directory foo and bar, will be automatically created.

  • After you select in the editor, you can right "search with google", "execute selected in console"

  • Edit code, line numbers will be marked on the right, insert, delete, modify different markers can click to diff and rollback

  • Change history> Local History, can be displayed, and can be restored to a history - right in the directory tree. (Note: does not matter with git)

Guess you like

Origin www.cnblogs.com/ABEL-Diving/p/11529120.html