search
HomeBackend DevelopmentPython TutorialPython IDE: A breakdown of the practical functions in PyCharm

So far, I have been using Eclipse for some years, and most of my time has been spent writing Python (installing the Pydev plug-in) and C++ (installing the CDT plug-in).

Recently I heard about PyCharm and its new free community version logr from a friend. This friend of mine has been using Eclipse for a long time and praised PyCharm highly, so I decided to at least try to use PyCharm when working from home. So far, I have fallen in love with it and even use PyCharm in my daily work (the community version is licensed by Apache2).

Below I will introduce some of the things that surprised me when using PyCharm.

Statement

I don't mean to criticize Eclipse or PyDev, I've used them for years and they are great! Please keep in mind that this is my personal experience and yours may be different.

Real-time comparison

PyCharm keeps track of changes you make in a file in real time by displaying a blue marker in the left column of the editor.

This is very convenient. I have been using the command "Compare against HEAD" in Eclipse to compare the changes before and after a file.

In PyCharm, you can see your changes at a glance. At the same time, clicking on the mark will display the previous content and a toolbar:

You can easily roll back these changes, view them in a detailed dialog box or paste the previous text to the clipboard.

Comparison preview when submitting

In Eclipse, when you commit changes, a commit dialog box shows you the list of files that will be committed.

You can double-click any of the items to view a comparison of the changes: At this time, if you see something in the code that you want to modify (such as a misspelled word, a paragraph

missing documentation, etc.), it’s not fun: you have to close everything (including the commit box with your carefully written commit comments), find the offending bit of code, correct it, and start over do it again.

PyCharm has the same features, but your changes are editable. I can't stress enough how great it is to be able to fix those mistakes on the spot!

I can easily fix typos like the ones above during the submission process.

An added bonus is that no matter what reason you close the commit dialog, when you try to commit again, it will retain those commit comments you just filled out.

Check

when submitting During the commit process, we can also perform some other options before the actual commit, such as "optimize imports (sort and remove unused imports)", check the pending items in the change set, etc.

An interesting point is the item "Perform Code Analysis". . .

Code review

You can ask PyCharm to perform "code review" operations on a file, directory, or entire project. It will

without actually executing the program. Find out the existing problems and corresponding improvement methods, such as type checking, static methods, violations of code specifications, etc.

As explained in the previous section, this can also be done automatically in the changed files at commit time. This is the result of a file review:

For some of these review results, you can also apply a fix recommendation. For example, for the suggestion "Function call can be replaced with set literal()", we can select the corresponding option to fix it.

PyCharm will interpret this sentence:

extensions = set(['.avi', '.mp4', '.mpg', '.mkv'])

Automatically replaced with:

extensions = {'.avi', '.mp4', '.mpg', '.mkv'}

You can turn off any review you don't want, including at the project level.

Refactor

I've been trying to rename a module, but I can't find that item in the menu. . . F2 doesn't help either.

Suddenly I noticed the "Refactor/Rename" item under the file submenu and thought. . . Could it be it? Indeed it is!

When you rename a module, PyCharm will ask you if you want to automatically modify all projects associated with it. Blessed!

There are many other refactoring projects, but so far I haven't had a chance to try them all.

 关于过时代码的提示以及改进建议

  PyCharm可以告诉你代码里面过时的结构块,并且提出一些改进建议。比如,我有像下面一段这样的代码:

with nested(open(filename1), open(filename2)) as (f1, f2):
 <代码块>

  PyCharm会明显的标注出nested:

  我用的是Python2.7,事实上你可以使用嵌套上下文管理器,但是,唉,我还得支持python的一些老版本,就保留了nested。

  但PyCharm提醒了我,这个事情本身还是很酷的。

 任务+特性 分支

  如同Eclipse一样(需要Mylin支持),PyCharm也支持基于任务的工作流(包括任务感知的上下文)。

  然而PyCharm本身自带了很多直接可用的连接器(GitHub,Mantis,Jira,Bugzilla,等等)。

  而且,当你开启一项任务时,它会询问你是否想要创建那个任务的一个特性分支,分支的名字可以配置。

  这就避免了必须手动创建一个新的分支,而这个操作确实挺繁琐的(拿到任务的ID,选择名称,等等)。

  这个是加分项。

 快速

  我观察到PyCharm在执行代码的自动完成时扫瞄代码的速度要远快于Eclipse,而且还不打断你当前的工作。

  当你想保存一个文件时,Eclipse会阻止你这么做因为它正在后台执行一个任务,这有多惹人烦。。。

 快速查看文档

  当你把光标挪到一个函数、方法,类或者别的什么上的时候,你会得到一个选项来浏览”快速文档“。看一眼:

  正如你看到的,它会用一种赏心悦目的格式展示方法的文档说明,还从代码使用说明中提示了参数的类型。。。即使该函数没有对应的文档说明,你还是会得到像下面这样的一个说明:

  很好!

 Docutils 支持

  PyCharm 还包括了对于doctils的一流支持,这让它很容易从集成开发环境中直接再生成文档。

  另一方面,它还包括了一个非常好的富文本(译者注:ReST即reStructuredTexteditor)编辑器(比Eclipse的IMHO好用的多):

 完善的插件系统

  跟据我的使用经验,在Eclipse里面安装插件是件挺痛苦的事情:

  •  很难找到你想要去的地方(提示: 帮助/安装新软件。。。);

  • 你没有一个单一的索引,所以你得去网上去找那些插件源;

  • 系统有时会因为库的依赖问题而崩溃,结果我就没装上那些我想要的插件(工作中还有其他人也同样遇到这个问题,最后不得不放弃);

  PyCharm的插件体验则要流畅地多。

  首先,它位于一个你认为它有可能会存在的地方:就在”设置”下面的一项:

你可以很容易地浏览插件:

  我快速安装了一个标记编辑器(和ReST一样),一个临时存放代码片段的插件,可以让我直接从选择的文本中快速地剪贴,并且预览代码,和SublimeText类似,还用一个漂亮的代码外观。

 结语

  目前为止就这些了。我会向我的朋友尽力展示一切我认为“看这有多酷”的事情。我使用PyCharm的时间很短,如果我发现还有更多有趣的事情值得再写一篇发表的话,我会继续写。

  原文链接: Bruno Oliveira   翻译: 伯乐在线 - 高磊

The above is the detailed content of Python IDE: A breakdown of the practical functions in PyCharm. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the performance differences in element-wise operations between lists and arrays.Explain the performance differences in element-wise operations between lists and arrays.May 06, 2025 am 12:15 AM

Arraysarebetterforelement-wiseoperationsduetofasteraccessandoptimizedimplementations.1)Arrayshavecontiguousmemoryfordirectaccess,enhancingperformance.2)Listsareflexiblebutslowerduetopotentialdynamicresizing.3)Forlargedatasets,arrays,especiallywithlib

How can you perform mathematical operations on entire NumPy arrays efficiently?How can you perform mathematical operations on entire NumPy arrays efficiently?May 06, 2025 am 12:15 AM

Mathematical operations of the entire array in NumPy can be efficiently implemented through vectorized operations. 1) Use simple operators such as addition (arr 2) to perform operations on arrays. 2) NumPy uses the underlying C language library, which improves the computing speed. 3) You can perform complex operations such as multiplication, division, and exponents. 4) Pay attention to broadcast operations to ensure that the array shape is compatible. 5) Using NumPy functions such as np.sum() can significantly improve performance.

How do you insert elements into a Python array?How do you insert elements into a Python array?May 06, 2025 am 12:14 AM

In Python, there are two main methods for inserting elements into a list: 1) Using the insert(index, value) method, you can insert elements at the specified index, but inserting at the beginning of a large list is inefficient; 2) Using the append(value) method, add elements at the end of the list, which is highly efficient. For large lists, it is recommended to use append() or consider using deque or NumPy arrays to optimize performance.

How can you make a Python script executable on both Unix and Windows?How can you make a Python script executable on both Unix and Windows?May 06, 2025 am 12:13 AM

TomakeaPythonscriptexecutableonbothUnixandWindows:1)Addashebangline(#!/usr/bin/envpython3)andusechmod xtomakeitexecutableonUnix.2)OnWindows,ensurePythonisinstalledandassociatedwith.pyfiles,oruseabatchfile(run.bat)torunthescript.

What should you check if you get a 'command not found' error when trying to run a script?What should you check if you get a 'command not found' error when trying to run a script?May 06, 2025 am 12:03 AM

When encountering a "commandnotfound" error, the following points should be checked: 1. Confirm that the script exists and the path is correct; 2. Check file permissions and use chmod to add execution permissions if necessary; 3. Make sure the script interpreter is installed and in PATH; 4. Verify that the shebang line at the beginning of the script is correct. Doing so can effectively solve the script operation problem and ensure the coding process is smooth.

Why are arrays generally more memory-efficient than lists for storing numerical data?Why are arrays generally more memory-efficient than lists for storing numerical data?May 05, 2025 am 12:15 AM

Arraysaregenerallymorememory-efficientthanlistsforstoringnumericaldataduetotheirfixed-sizenatureanddirectmemoryaccess.1)Arraysstoreelementsinacontiguousblock,reducingoverheadfrompointersormetadata.2)Lists,oftenimplementedasdynamicarraysorlinkedstruct

How can you convert a Python list to a Python array?How can you convert a Python list to a Python array?May 05, 2025 am 12:10 AM

ToconvertaPythonlisttoanarray,usethearraymodule:1)Importthearraymodule,2)Createalist,3)Usearray(typecode,list)toconvertit,specifyingthetypecodelike'i'forintegers.Thisconversionoptimizesmemoryusageforhomogeneousdata,enhancingperformanceinnumericalcomp

Can you store different data types in the same Python list? Give an example.Can you store different data types in the same Python list? Give an example.May 05, 2025 am 12:10 AM

Python lists can store different types of data. The example list contains integers, strings, floating point numbers, booleans, nested lists, and dictionaries. List flexibility is valuable in data processing and prototyping, but it needs to be used with caution to ensure the readability and maintainability of the code.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software