Python IDE: A breakdown of the practical functions in PyCharm

巴扎黑
Release: 2017-04-30 15:23:55
Original
1514 people have browsed it

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'])
Copy after login

Automatically replaced with:

extensions = {'.avi', '.mp4', '.mpg', '.mkv'}
Copy after login

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): <代码块>
Copy after login

  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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!