Editing Code with PyCharm Community Edition

Editing Code with PyCharm Community Edition

This is the first part of the promised PyCharm review, where we look at the Code Editor in PyCharm Community. Our follow up will look at the Plug-ins and other features that make it a fully-fledged IDE.

PyCharm Community?

Glad you asked! PyCharm Community is a free, open-source IDE supported by JetBrains and regularly updated. There is a paid Professional version with more features which we'll cover at a future date.

With my background in .NET, PyCharm was used in Windows, mostly while going through training from Talk Python to Me. Versions for Linux and Mac are also available.

PyCharm is popular, having advanced in the github Top IDE index to 12th for April 2017. That probably includes both paid and Community editions. enter image description here

Editor First Impressions

When you first load up a project in PyCharm Community, you´ll notice a clean but efficient interface.

PyCharm Community new Project

There is a project viewer showing your folder layout and the code pane is clear to read with decent code highlighting of different sections. The help section offers a good reference including Key-shortcuts, Demos and a way to turn off the Tip of the Day.

enter image description here

Core of a Code Editor

If you've ever used ReSharper from JetBrains, then you'll immediately notice a similarity between feel and functionality between that and PyCharm Community From our look at the features of an editor in Code Editor or IDE you can see that PyCharm ticks fills the basic requirements, including

  • clear syntax highlighting which can be configured from the Settings section (under Editor -> Colors & Fonts -> Python) .
  • smooth autocomplete which updates as you type, with none of the lag sometimes found in Visual Studio.
  • integrated source control with github support included by default.

Then there are some bonus features

  • auto-imports for referenced packages, alerting you if a package should be included and offering to add the reference for you
  • solid Refactoring support which JetBrains is renowned for, allowing you to easily Rename, Move, Extract and Delete parts of your code with PyCharm doing the heavy lifting.
  • spellchecking dictionaries which catch your typos in text strings, comments and other textual content. User-defined words can be added and the dictionaries configured from the settings --> Editor --> Spelling section.
  • A TODO list which will find any comments with "TODO" and show them in the TODO window, allowing you to keep a list of things to be aware of or possibly search for in an unfamiliar code base.
  • A lightbulb icon which give suggested fixes for code warnings or errors, and the fixes can be implemented via shortcut keys.

Code Navigation

As well as spending lots of your time as a code reading code, you'll also spend lots of time moving between classes, files and methods... PyCharm has a full array of shortcuts for moving between Classes, Files and Declarations (possibly my favourite). Severa of the other shortcuts in the Navigation menu are also worth learning.

Navigation menu

3 Python-Specific Features

There are a few things specific to Python where PyCharm shines...

  1. Indentation: PyCharm will handle your indentation for you, which is a regular feature of many IDEs, but super-important to Python as excess spaces can cause severe problems!
  2. PEP 8 Notifications: A style guide for Python code created by the author of Python, PEP 8 is a way to keep consistency between different code bases. PyCharm provides recommendations when PEP 8 is being broken.
  3. Magic methods: Special methods of PyCharm (such as init) can be inserted from autocomplete, creating all of the code snippet needed to implement the most basic version of the method.

Configuring the Editor

From the settings screen of PyCharm you can access and configure many of the editor settings, from Code Completion to Tabs Appearance, Fonts and Spelling.

enter image description here

One of my favourite is the Code Style, where you can specify how you want the auto-formatting to work for Python, fiddling with tab sizes, wrapping and blank lines amongst others.

enter image description here

Final Thoughts

The editor for PyCharm Community is fully featured and fast, although not as easy to use as a simple editor. There may be more updates as I learn more about PyCharm Community. You can leave a comment here or tweet @DuncanThom with anything you think should be included!


Duncan Thomson

A Remote Software and Database Contractor specialised in Umbraco, Duncan works from wherever he finds himself. He is the co-organiser of the Python Exeter and Data Science Exeter meetup groups and speaks about Remote Working, Umbraco, Python and .NET Outside of work he is keen on travel, random generation, foreign languages and good food.

comments powered by Disqus