Home  >  Article  >  Backend Development  >  After installing these 14 plug-ins, PyCharm is really invincible.

After installing these 14 plug-ins, PyCharm is really invincible.

Python当打之年
Python当打之年forward
2023-08-11 15:24:521697browse

After installing these 14 plug-ins, PyCharm is really invincible.

#1. Key Promoter ##. It is equivalent to a shortcut key management master. It is always there:

Teach you which shortcut operation you should use to improve efficiency for your current operation. ?

Remind you that you have not set a shortcut key for this operation at the moment. How about setting one up quickly?

  • With

    Key Promoter
  • For example, if I use the mouse to click on

    Find in Path

    , it will pop up a window in the lower right corner to prompt you which shortcut key to use.
  • After installing these 14 plug-ins, PyCharm is really invincible.

    2. Vim in PyCharm

    In most scenarios, the efficiency and accuracy of using the mouse, It is far inferior to keyboard shortcuts (provided that you have mastered the shortcut keys quite proficiently), you have to admit this.

    Vi can meet all your needs for text operations, and is more efficient and geekier than the visual interface. If you are like me, you are a loyal vim fan. After installing Pycharm, you will definitely install the ideaVim plug-in as soon as possible. It allows us to use vim to edit code in Pycharm.

    The installation method is as follows. After installation, you need to restart Pycharm to take effect.

    After installing these 14 plug-ins, PyCharm is really invincible.

    3. Markdown in PyCharm

    Rich text formatting documents is a very painful thing. For programmers to write documents, the best recommendation is to use Markdown. All my blog diaries are written using Markdown.

    The code downloaded from Github usually comes with a README.md file, which is a Markdown format file.

    PyCharm does not have the Markdown plug-in installed by default, so it cannot display text in Markdown format and displays the original text.

    Therefore, if you want to read Markdown documents in PyCharm, you can install the Markdown support plug-in.

    There are two installation methods:

    1. The first, the most convenient, is that you open an MD document and PyCharm will prompt you to install it.

    2. Search and install from the plug-in store.

    After installing these 14 plug-ins, PyCharm is really invincible.

    The effect is as follows

    After installing these 14 plug-ins, PyCharm is really invincible.

    4. Jupyter Notebook in PyCharm

    Before using Jupyter, you must first install it

    $ pip install jupyter

    Then follow the instructions below to create a new Notebook , you can start operating.

    After installing these 14 plug-ins, PyCharm is really invincible.

    This interface does not seem to match the style of Jupyter

    After installing these 14 plug-ins, PyCharm is really invincible.

    But there is no difference in use, remember Just hold three shortcut keys (the following refers to Mac, Windows is different)

    • Ctrl Enter: run the cell

    • Option shift Enter: Debug the cell

    • Shift Enter: Insert a new cell

    After installing these 14 plug-ins, PyCharm is really invincible.

    As long as you install Jupyter, your use of the Python Console will automatically change to Jupyter mode

    After installing these 14 plug-ins, PyCharm is really invincible.

    5. Regex Tester in PyCharm

    Regex Tester is a third-party plug-in for PyCharm that can test regular expressions.

    Follow the entry below to install the Regex Tester plug-in:

    After installing these 14 plug-ins, PyCharm is really invincible.

    After the installation is complete, there is no need to restart PyCharm. Click the small rectangular button at the bottom left of the PyCharm interface. Regex Tester option can be found.

    After installing these 14 plug-ins, PyCharm is really invincible.

    点击进入后,就出现了如下界面。我随手写了个匹配手机号码的正则(不一定准确),匹配到的字符串背景会被高亮。右上方还有一些选项如大小写敏感,多行模式等,可根据需要进行选择。Regex Tester 还提供了Split,Replace功能等。

    使用效果如下:

    After installing these 14 plug-ins, PyCharm is really invincible.

    6. Use Bash in Windows

    在 Windows 上的 cmd 命令和 Linux 命令有不少的差异,比如要列出当前目录下的所有文件,Windows 上是用 dir ,而 Linux 上则是用 ls -l

    对于像我这样熟悉 Linux 的开发者来说,Windows 的 那些 CMD 命令带来的糟糕体验是无法忍受的。

    After installing these 14 plug-ins, PyCharm is really invincible.

    在弹出的 Bash 窗口,你可以敲入你想使用的 Linux 命令,是不是舒服多了。

    After installing these 14 plug-ins, PyCharm is really invincible.

    7. Auto PEP8 in PyCharm

    pep8 是Python 语言的一个代码编写规范。如若你是新手,目前只想快速掌握基础,而不想过多去注重代码的的编写风格(虽然这很重要),那你可以尝试一下这个工具 - autopep8

    首先在全局环境中(不要在虚拟环境中安装),安装一下这个工具。

    $ sudo pip install autopep8

    然后在 PyCharm 导入这个工具,具体设置如下图

    Name: AutoPep8
    Description: autopep8 your code
    Program: autopep8
    Arguments: --in-place --aggressive --aggressive $FilePath$
    Working directory: $ProjectFileDir$
    Output filters: $FILE_PATH$\:$LINE$\:$COLUMN$\:.*
    After installing these 14 plug-ins, PyCharm is really invincible.

    我随意写了一段不符合 pep8 规范的代码。

    After installing these 14 plug-ins, PyCharm is really invincible.

    点击右键,选择 External Tools -> AutoPep8

    After installing these 14 plug-ins, PyCharm is really invincible.

    看一下效果,还是挺明显的。

    After installing these 14 plug-ins, PyCharm is really invincible.

    你可能会说,Pycharm 本身就自带这个功能了呀,快捷键 Command+Option+L ,就可以实现一键pep8了。你可以对比一下,Pycharm 自带的代码 pep8 化功能 并没有像这个autopep8 来得彻底。我相信你最终的选择肯定是后者。

    8. Test RESTful Web Service

    PyCharm 的 Test RESTful Web Service工具提供了RESTful接口测试界面,如下图所示,提供了get、post,put等http方法,其中的Request子界面headers,Parameters,Body等功能,Response子界面用于显示返回值,Response Headers用于显示返回的消息头。

    为了演示,我先使用 Flask 写一个 HTTP 接口

    from flask import Flask, request
    
    app = Flask(__name__)
    
    
    @app.route('/hello')
    def index():
        name = request.args.get('name')
        return '你好,' + name
    
    if __name__ == '__main__':
        app.run()

    并运行它开启服务,访问地址是:http://127.0.0.1:5000/

    After installing these 14 plug-ins, PyCharm is really invincible.

    通过下图方式打开 Test RESTful Web Service

    After installing these 14 plug-ins, PyCharm is really invincible.

    The following interface will appear. Fill in the following information in the red box

    After installing these 14 plug-ins, PyCharm is really invincible.

    and then click on the leftmost Click the Run button to send an http request to the server.

    After installing these 14 plug-ins, PyCharm is really invincible.

    9. Execute Selection in Console

    When you want to write a simple test code, Maybe you will write directly using Python Shell like this

  1. #. The disadvantage is that there is no auto-completion.

  2. #Open a new file in PyCharm. The disadvantage is that you need to create a new file and delete it after you are done.

Today I will introduce to you a new method that can completely avoid the shortcomings of the above two methods.

That isExecute Selection in Console, it can be said to be Run in Anywhere.

Just write the code in the current file, and then put the cursor After selecting, right-click Execute Selection in Python Console or use the shortcut key option shift E (alt shift E on Windows).

After installing these 14 plug-ins, PyCharm is really invincible.

Then PyCharm will pop up a Python Console window, and then run the code you selected.

After installing these 14 plug-ins, PyCharm is really invincible.

One of the highlights is that using this method, PyCharm will automatically handle the indentation for us (when we select, there is indentation in front, but when executing , the excess indentation in front will be automatically removed)

10. CodeGlance

If you have used Sublime Text before, switching to other code editors will be more or less uncomfortable because it is very Few editors come with a preview scroll bar like Sublime.

In PyCharm, there is no problem that cannot be solved. If there is, then install a plug-in.

To use this preview scroll bar in PyCharm, just install the CodeGlance plug-in. The effect is as follows

After installing these 14 plug-ins, PyCharm is really invincible.

11. Chinese Plugin

I often hear it a lot Beginners complain, why is PyCharm all in English? It’s so hard to learn.

In the past, I would tell them that learning programming language and English is a very important ability. You must not be afraid of it or avoid it, but learn it and adapt to it. If you don’t even have an IDE If you can't adapt to it, then don't learn programming.

Now, JetBrains has officially released a Chinese plug-in, and its name is: chinese. When searching in the plug-in market, it ranks first, with 400,000 downloads. Compared with the second-ranked folk Chinese plug-in, Plug-ins are simply out of this world.

After installing these 14 plug-ins, PyCharm is really invincible.

Click INSTALL After installation, you will be prompted to restart to take effect.

After installing these 14 plug-ins, PyCharm is really invincible.

After the restart is completed, what is displayed in front of us is an interface that is both familiar and unfamiliar, and all menu bars have become Chinese.

After installing these 14 plug-ins, PyCharm is really invincible.

After clicking on the settings, it can be said that Chineseization has been basically achieved, with only a small amount of English remaining (could it be because it is easier to retain these words in English than after translation) Do you understand? Just like socket and socket.), but personally I feel that it does not affect the use at all.

After installing these 14 plug-ins, PyCharm is really invincible.

12. Profile in PyCharm

在 Python 中有许多模块可以帮助你分析并找出你的项目中哪里出现了性能问题。

比如,常用的模块有 cProfile,在某些框架中,也内置了中间件帮助你进行性能分析,比如 Django ,WSGI。

做为Python 的第一 IDE, PyCharm 本身就支持了这项功能。而且使用非常方便,小白。

假设现在要分析如下这段代码的性能损耗情况,找出到底哪个函数耗时最多

import time

def fun1():
    time.sleep(1)

def fun2():
    time.sleep(1)

def fun3():
    time.sleep(2)

def fun4():
    time.sleep(1)

def fun5():
    time.sleep(1)
    fun4()

fun1()
fun2()
fun3()
fun5()

点击 Run -> Profile '程序' ,即可进行性能分析。

After installing these 14 plug-ins, PyCharm is really invincible.

运行完毕后,会自动跳出一个性能统计界面。

After installing these 14 plug-ins, PyCharm is really invincible.

性能统计界面由Name、Call Count、Time(ms)、Own Time(ms) ,4列组成一个表格,见下图。

  1. 表头Name显示被调用的模块或者函数;Call Count显示被调用的次数;Time(ms)显示运行时间和时间百分比,时间单位为毫秒(ms)。

  2. 点击表头上的小三角可以升序或降序排列表格。

  3. 在Name这一个列中双击某一行可以跳转到对应的代码。

  4. 以fun4这一行举例:fun4被调用了一次,运行时间为1000ms,占整个运行时间的16.7%

点击 Call Graph(调用关系图)界面直观展示了各函数直接的调用关系、运行时间和时间百分比,见下图。

After installing these 14 plug-ins, PyCharm is really invincible.

右上角的4个按钮表示放大、缩小、真实大小、合适大小;

  1. 箭头表示调用关系,由调用者指向被调用者;

  2. The upper left corner of the rectangle displays the name of the module or function, and the upper right corner displays the number of calls;

  3. Rectangle The running time and time percentage are displayed in the middle;

  4. The color of the rectangle indicates the trend of running time or time percentage: red > yellow-green > green, as shown in the figure It can be seen that the rectangle of fun3 is yellow-green and the rectangle of fun1 is green. The running time of all fun3 is longer than that of fun1.

  5. It can be seen from the figure that Test.py directly calls the fun3, fun1, fun2 and fun5 functions; the fun5 function directly calls the fun4 function; fun1, fun2 , fun3, fun4 and fun5 all directly call the print and sleep functions; the total running time of the entire test code is 6006ms, of which the running time of fun3 is 1999ms, which accounts for 33.3% of the time, that is, 1999ms / 6006ms = 33.3% .

13. Json Parse in PyCharm

During the development process, the verification is often To check whether the JSON string is legal, in the past my approach was to open the online website https://tool.lu/json/ and directly beautify it to verify it. Only the JSON format is correct and legal can it be beautified.

After installing these 14 plug-ins, PyCharm is really invincible.
img

Until later I discovered that there is a plug-in in PyCharm specifically to do this, that is JSON Parser, in the plug-in market After installation, restart PyCharm and you will see it in the right sidebar.

After installing these 14 plug-ins, PyCharm is really invincible.
img

14. Inspect Code in PyCharm

For compiled Languages, such as Java, need to compile the code into a machine-recognizable language before it can be run. During the compilation process, the correctness of the program can be checked by analyzing or checking the syntax, structure, process, interface, etc. of the source program to find out Code hides errors and defects. This process is called static code analysis inspection.

For an interpreted language like Python, the code is translated while running and does not need to go through the compilation process. Many errors that cannot be seen immediately with the naked eye can usually only be discovered after running (running is so convenient anyway).

Because Python is so convenient to run, we don't need to pay much attention to static analysis tools.

But that’s not to say that static analysis tools have no place at all. I think they still do.

If your coding skills are not very mature, there may be many hidden bugs in the code. Since Python is not interpreted until it is run, only one bug can be found at a time, and 100 bugs need to be found. The bug needs to be run 100 times. The number is a bit exaggerated. In fact, what I want to say is that if so many errors can be discovered through a static check and corrected immediately, the efficiency of development and debugging can be improved. Of course, this does not mean that all errors in static analysis can be discovered in advance. I hope you don't misunderstand this.

As the most powerful IDE for Python, PyCharm itself has this function built-in and does not require you to install any plug-ins.

You only need to click on the project folder as shown below, then right-click and select Inspect Code to turn on static inspection.

After installing these 14 plug-ins, PyCharm is really invincible.

#My static inspection of the open source component nova found that there are thousands of irregularities in it.

After installing these 14 plug-ins, PyCharm is really invincible.

over.


The above is the detailed content of After installing these 14 plug-ins, PyCharm is really invincible.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:Python当打之年. If there is any infringement, please contact admin@php.cn delete