Feature Spotlight: Reformatting Python code with Pycharm’s intentions

Happy Friday everyone!

Did you have a chance to read one of my previous posts on how PyCharm helps you write clean and maintainable Python code? As a quick recap: Pycharm highlights code style violations with both PEP8 and custom inspections, and it also allows you to apply automatic quick-fixes to keep your code in consistent format.
Today I’m going to cover another feature that you may find handy for writing professional and quality code. It’s called Code intentions.

The main difference between PyCharm’s code inspections and intentions is that while inspections provide quick-fixes for code that has potential problems, intentions help you apply automatic changes to code that is most likely correct.

Here’s how it works:

When editing absolutely correct code, the yellow bulb sometimes appears in the editor:


That signals that the automatic action is available to be applied in place. To get a list of intentions applicable to the code at the caret, just press Alt + Enter:


In this particular situation PyCharm offers to convert the lambda to a normal function. Just hit Enter and it will do the job for you:


It also highlights the new function name and when you change it, it automatically changes the function call:


There is a huge number of different code intentions available for Python and all other supported languages including JavaScript, SQL, CSS, and other. You can see them all as well as enable or disable some of them in Settings (Preferences for Mac OS) | Editor | Intentions:


Another way to get to the intentions settings or simply disable the unwanted intention is to hit right arrow on the intention in the editor:


I bet you’ll like this feature if you haven’t tried it before.

Have a great weekend and see you next week!


Posted in Cool Feature | 3 Comments

PyCharm 4.0.5 RC2 is available

Having announced the PyCharm 4.0.5 RC build a week ago, today we’ve published the PyCharm 4.0.5 RC2 build 139.1525, which is already available for download and evaluation from the EAP page.

This build has only two new fixes that can be found in the release notes: a fix for deprecation warning when using Behave and an important fix for debugging multi-process Pyramid and Google App Engine projects.

We encourage you to download PyСharm 4.0.5 RC2 build 139.1525 for your platform and test the latest fixes. Please report any bugs and feature request to our Issue Tracker. It also will be available shortly as a patch update from within the IDE.

Develop with pleasure!
-PyCharm Team

Posted in Early Access Preview | 1 Comment

PyCharm 4.0.5 RC is available

We are happy to announce the availability of PyCharm 4.0.5 Release Candidate. Since the previous bug-fix update in early January we’ve gathered a lot of fixes for different PyCharm’s subsystems. Actually we’re almost ready to release them to you as PyCharm 4.0.5, but before we do that, we’d like to make sure that this build doesn’t hide any surprises. That’s why we’re releasing PyCharm 4.0.5 RC today.

Installers for PyCharm 4.0.5 RC (build 139.1485) can be found on Early Access Preview page.

The complete list of changes is in the PyCharm 4.0.5 RC release notes. The most notable among them are: a critical fix for broken code insight for PyPy, a couple of fixes for unresolved NumPy functions, and a few important fixes for Django 1.7 support.

Patch updates from the previous versions should be available soon. Just make sure you’ve enabled the “Early Access Preview” update channel in your update settings. In case you want to keep your current PyCharm installation untouched but still want to try the new RC version, please don’t use the patch update – install the new version alongside from scratch instead.

We hope there’ll be no major bugs in this build and we’ll be able to give it a green light as PyCharm 4.0.5 within the next week.

As always, please report any problem you found to our public issue tracker. By doing so you help us make PyCharm better.

Follow us on twitter to receive our latest news.

Develop with Pleasure!
-PyCharm team

Posted in Early Access Preview | 4 Comments

Feature Spotlight: Find Usages & Locate Duplicates in Python Code

Happy Friday everyone,

In the last week’s blog post I covered different refactoring capabilities of PyCharm. Today I’ll continue highlighting different handy features and show you some more tools that help you keep your code under full control.

One of the features that every developer uses on the daily basis is Find/Replace. It’s supported in every code editor, and PyCharm is no exception: Ctrl+F/Ctrl+R. Besides, PyCharm supports a number of subsidiary functions, such as Find Next/Previous Occurrence, Find/Replace in Path, Select all Occurrences, etc. They all are available under the Edit | Find menu item:


While some of these features are pretty common, others really stand apart thanks to PyCharm outstanding code intelligence. Find usages is one of such noticeably smart features that deserves a closer look.

1. Find usages
Just press Alt + F7 on any symbol at the caret ( no matter if the symbol is a class, method, field, parameter, or another statement) and get a list of references grouped by type of usage, module and file. This feature is really fast and gets you first results almost instantly. More results appear as the IDE finds them:


By default the results should be grouped by usage type, if not you can enable this by pressing Ctrl(Cmd for Mac) + Alt + T or by clicking the corresponding button on the sidebar:


2. Settings
If you want to set custom options for the Find Usages algorithm, you can use Shift + Alt + Ctrl + 7 (Shift + Alt + Cmd + 7 for Mac):


3. Quickpopup
To see the results quickly in place, simply press Alt + Ctrl + 7 (Alt + Cmd + 7 for Mac):

4. Highlight overridden methods
Another useful aspect of highlighting usages in PyCharm is that you can easily find the methods that are overridden for a particular class. Just put the caret at the statement and press Shift + Ctrl + F7 (Shift + Cmd + F7 for Mac). If there are multiple classes, you will be asked whose methods to highlight:

5. Highlight usages in File
Sometimes its useful to quickly see all usages of the variable or method within a file right in the editor. Highlight usages in File (Ctrl + Shift + F7) works perfect in this case:


Locate Duplicates

It’s not a secret that one of the most annoying problem of every project is duplicated code. Obviously any developer tries to get rid of such redundancies. Thanks to PyCharm code intelligence, Locate duplicates tool allows you to examine your code and find different code duplicates. This tool works for different languages and is highly configurable.
To use this tool go to Code | Locate Duplicates. It will ask you for an analysis scope specification:


then you can specify some other options before give it a go:


You can set supported languages that will be analysed within your scope as well as other configurable options for fine tuning the analysis.

On the last step after clicking OK, it will show you the list of code duplicates found, as well as the tool to review these duplicates and navigate between them:


After finding duplicates you might want to use one of the refactoring features described in my previous blog post in order to get rid of them.

I hope I’ve been helpful and shed some light on these advanced PyCharm search features.

Have a great weekend and see you next week!

Posted in Cool Feature | 4 Comments

Feature Spotlight: Refactoring Python code

We all know that code can’t be crafted ideally from the beginning, especially in large projects. There is always a need to change something during the active development or maintenance stages. In fact refactoring is something you do all the time in small steps. You don’t simply decide to refactor – you change your code because you want to do something else, and refactoring helps you do that other thing.

As Martin Fowler says: “Refactoring is a controlled technique for improving the design of an existing code base. Its essence is applying a series of small behavior-preserving transformations, each of which is “too small to be worth doing”. However the cumulative effect of each of these transformations is quite significant.”

Refactorings can be a simple rename of a variable or extracting a superclass from the body of an existing class. PyCharm provides many refactorings for the various languages it supports. It carries them out automatically, making sure existing code is updated and will not break.

Today we’ll take a look at the refactoring features available in PyCharm that reduce the risk of introducing errors while you are carrying out the restructuring.

Note: While this blog post covers refactorings for Python code, the IDE also supports refactorings for other languages like JavaScript, HTML and so forth. Give refactoring a try in these languages as well.

Refactoring in PyCharm

Before we dive into all available refactorings, let’s see what a typical refactoring looks like. Sure, they all do different things, still there are some things they have in common. Let’s try renaming a class in our code.

To do this, we can use the Refactor | Rename… context menu on a class name, or place the cursor on it and use the Shift+F6 keyboard shortcut to invoke the rename refactoring immediately:


For every refactoring, we’ll get a different dialog in which we can provide the options for it. In this case we have to provide a new name for the class we’re about to rename. Some of the options in this dialog will be available for other refactorings as well: we can (optionally) search in comments and strings, search for text occurrences, and so on.

When invoking a refactoring in PyCharm, the IDE will:

  • Perform the refactoring
  • Track down and correct the affected code references automatically
  • Warn about occurrences it cannot update automatically
  • Save the previous state of your code, so you can always revert safely

If you are unsure about the outcome, consider clicking the Preview button before running the refactoring. It will open the Find Refactoring Preview tool window and show you all of the actions the refactoring will perform:


In this case, it will:

  • Rename the class and its derived class
  • Update all code references
  • Update one of the import statements in the project

We can filter and search in this tool window. Also we can optionally select one of the occurrences and use Delete to have PyCharm ignore it whenever we perform the refactoring:


This may come in handy when we’re also searching and replacing in comments and strings. Usually we will not exclude actual code refactorings.

Clicking Do Refactor will perform the refactoring and update our project’s codebase.

Another important thing to know is that PyCharm lets you undo everything, and that includes refactorings, no matter how complex code transformations they cause. Just press Ctrl + Z (Cmd + Z for Mac), and you’re back to where you were before inadvertently scrambling a few thousands lines of code. Another way to get back in code state is to use Local history by invoking Ctrl + Shift + A (Cmd + Shift +A for Mac) and typing “Local history”:


More information on local history can be found in one of our previous blog posts.

The Refactor This Action

While most refactorings in PyCharm have their own shortcuts, we may not know all of them. We may also be unfamiliar with the various refactorings available for a given file or a symbol. And that’s where the Refactor This action comes in handy!

In the Project View, Structure Tool Window, Editor or a UML Class Diagram, place the cursor on any file or symbol and use the Refactor | Refactor This context menu or press Ctrl+Shift+Alt+T (Ctrl-T on Mac OS X). This will display a pop-up with the different refactorings that we could carry out:


Using the up/down keys and Enter (or the numeric identifier for each entry in the pop-up) we can invoke the refactoring.

Available refactorings

PyCharm comes with lots of refactorings. I won’t go over all of them them here, but rather list the most essential ones. For every refactoring, I’ll add a link to the PyCharm Web Help which contains a full description of all available options for a given refactoring.

Note: All refactorings are available from the Refactor context menu or via their respective keyboard shortcuts.

That’s all for today. I hope you’ll enjoy this wide range of refactoring capabilities provided by PyCharm.

See you next week, and refactor safely!

Posted in Cool Feature | 1 Comment

Feature Spotlight: Navigating Python Code

As programmers we read more than we write. And when projects we’re working on become larger and more complex, the problem of understanding and getting around unfamiliar or even your own code becomes more and more essential. The faster and easier you navigate through the code – the faster you can read it, understand its concepts and flows. Eventually this reflects on how productive you are in general.

Simple textual search is neither convenient nor effective when working with large projects. Sorting out thousands lines of Python code without special assistance can turn into an extremely difficult and time consuming task.

Here come different tools that make developer’s life much easier. It can be a plugin for a text editor such as ctags or vimpy for the Vim editor, or SublimeCodeIntel, SublimeRope, SublimePythonIDE, or whatever else for Sublime Text.

Using plugins for a text editor has several downsides, though. For example, if you want to turn Sublime or Vim into something that will provide you code completion, navigation, refactorings, add PEP8 checks or do linting for Python, you’ll have to install several additional plugins which won’t share information about the code with each other but rather maintain each own knowledge base.

Now, what if you use other languages besides Python in your project, such as JavaScript, HTML or even Django templates? You’ll have to find a particular plugin that supports your language. Hopefully this would work, however eventually you’ll end up with quite a messy arrangement – an editor with a bunch of plugins working independently and unreliably – hard to set up and a pain to maintain.

Fortunately, we’ve got PyCharm that makes things easy and smooth, boosting your productivity along the way. What distinguishes PyCharm the most is that being an IDE it seamlessly integrates different subsystems that are happy to work together, sharing data and source code knowledge between each other. This way PyCharm’s advanced code analysis, both static and dynamic, affects different subsystems, such as code completion, navigation, refactorings etc. The IDE knows everything about your code and you get the top-notch navigation solution that lets you focus on the actual development and makes you as fast and efficient as you can be.

Lets take a closer look at what PyCharm has to offer in regard to source code navigation:

1. Recent files
Most of the time you work with a finite set of files. It means you have to switch between them quickly all the time. The real time-saver here is the action called Recent files via Ctrl + E (Cmd + E for Mac). By default the focus is on the last accessed file. In the meantime you can open any tool window through this action:


Another useful feature similar to Recent files is Recently edited files, available via Shift + Ctrl + E (Shift + Cmd + E for Mac). This is the easiest way to get back to the code you are working on.

2. Structure
When you are not switching between files you’re probably navigating within one. The shortest way to do it is to press Ctrl + F12 (Cmd + F12 for Mac). The popup shows you the structure of file and allows you to quickly navigate to any item. Just as always you don’t need to touch your mouse:


Note that the speed search works here as well. Hit the shortcut twice to display inherited members.

3. Switcher
Just like the task switcher in an operating system, PyCharm provides a switcher between opened files and tool windows. The action is available via Ctrl+Tab:


4. Jump to navigation bar
Another useful feature worth to mention is Jump to navigation bar via Alt + Home (Alt + ↖ for Mac). The navigation bar at the top of the window is useless most of the time. That’s why developers usually hide it and call on demand via a shortcut.
The navigation bar supports speed search and other actions, such as code generations, documentation popup, etc:


5. Navigate between methods
If you need to jump over the methods quickly, just press Alt + ↑↓ (Ctrl + ↑↓ for Mac):


A similar action for navigating between braces is available via Ctrl + { and Ctrl + } (Cmd + { and Cmd + } for Mac).

6. Navigate to anything
The next feature, which is one of the most used in PyCharm, is Navigate to Class, File and Symbol.
This feature is available via Ctrl + N (Cmd + N for Mac) and supports sophisticated expressions, including camel humps, path, line navigate to, middle name matching, and many more. If you call it twice it shows you the results out of the project classes:


Just like for classes it works for files as well, via Ctrl + Shift + N (Cmd + Shift + N for Mac). The results are sorted by relevance to the expression:


And finally the most tricky feature is to navigate to a symbol via Ctrl + Alt + Shift + N (Alt + Cmd + Shift + N for Mac). The IDE constantly maintains the index of all symbols in the project (and within libraries as well) for quick resolve and navigation. You can type an expression and find a method or a field you need in a second:


7. Select in
If you need to open the file in a particular tool window (or Finder/Explorer) you can do it via Select In action by pressing Alt + F1:


8. Method Call hierarchy

Thanks to it’s fantastic static code analysis capabilities, PyCharm intelligently analyses the code and builds a call hierarchy trees for method calls in different scopes. Place the caret to a method name and press Ctrl + Alt +H (Cmd + Alt + H for Mac):


9. Other notable navigation features

  • Navigate to line number via Ctrl + G (Cmd + G for Mac)
  • Navigate to Custom Folding via Ctrl + Alt + Period
  • Related files via Gutter
  • Navigate to declaration via Ctrl + B (Cmd + B for Mac)
  • Navigate to implementations via Ctrl + Alt + B (Alt + Cmd + B for Mac)
  • Navigate to type declaration via Ctrl + Shift + B (Shift + Cmd + B for Mac)
  • Navigate to Super Method via Ctrl + U (Cmd + U for Mac)
  • Navigate to the last edit location via Shift + Ctrl + Backspace (Shift + Cmd + Backspace for Mac)
  • Navigate to the next error or warning via F2
  • Navigate to a related unit test via Shift + Ctrl + T (Shift + Cmd + T for Mac)
  • Navigate to a related symbol via Ctrl + Alt + Home (Cmd + Alt + Home)

All the navigational features mentioned here as well as other helpful functions are accessible via special Navigate system menu:


I hope you’ll enjoy these slick navigational features and save a great deal of time while at it.
And if you’d like to learn more about PyCharm’s code navigation capabilities, see our tutorial or online help.

Have a nice day!

Posted in Cool Feature | Leave a comment

Feature Spotlight: Python Debugger and ‘Attach to Process’

Happy Friday everyone,

Today I’d like to highlight some recent changes and improvements in PyCharm`s Python debugger and explore the brand new attach to process in more detail.

Previously PyCharm used a special fork of the PyDev debugger with some PyCharm-specific changes, as well as our own unique features like GEvent debugging and breakpoints at Django templates. Before releasing PyCharm 4, we decided to contribute to open-sourced software and merged our debugger code with that from the original PyDev repository. Now the work on the debugger continues from both sides (PyCharm and PyDev) in one place. The merged source code now lives at https://github.com/fabioz/PyDev.Debugger and pull requests are greatly appreciated!

As a result of the unification and the work done since PyCharm 3.4, the debugger in PyCharm 4 has grown more powerful. We’ve added the Referring Objects view, Jinja 2 templates debugging, and other small improvements. Still, the most notable debugger feature introduced in PyCharm 4 is attach to process.

Using this feature you can connect the PyCharm debugger with any running Python process and debug in the attached mode.

Note: ‘Attach to Process’ functionality is available in both PyCharm Community Edition and PyCharm Professional Edition starting with v4.0. This feature is supported on all Windows, Linux and Mac platforms.

Let me show you how it works.

Say we have some long running application that we want attach to. In my example I’ll use a simple graphical Minecraft-inspired application that I found on GitHub.

I have opened the project in PyCharm and launched it using standard run/debug configurations:


The project is running, so now I can attach the debugger to it. For that I go to Tools and select Attach to Process. PyCharm shows the list of running Python processes in our system. I select the Minecraft process and click OK:


PyCharm automatically shows the debugger console with the message that the debugger has successfully connected to the process:


From this point on, debugger works in the attached mode. Let’s make use of it and stop at some line of code. To do that, in the editor I put a breakpoint on the line with some reachable code. In my example I’ve put the breakpoint on the line containing the definition of the cube_vertices function, which is being called a lot. In a few seconds, once the process reaches the breakpoint, PyCharm will stop at the breakpoint and show us the debugger with frames, variables and watches views:


Now we can use the debugger as usual – stepping into/over, pausing and resuming the process, evaluating variables and expressions, and changing the runtime context:


That’s it! Hopefully you’ll appreciate this addition to the new joint-effort PyCharm debugger, along with other handy features introduced in the latest version of PyCharm.

And if you’re craving for yet more details on PyCharm debugger, see this tutorial or the online help.

See you next week,

Posted in Cool Feature | 8 Comments

‘Best Interactive Programming Course with Python’ Contest in Full Swing

A month ago we announced the launch of the educational contest for the Best Interactive Programming Course with Python. A number of participants have already joined, but with 3 more weeks to go until the end of the contest there’s still plenty of time to make your contribution. There are multiple prizes in several categories, so why not give it a shot?


Register your entry on the contest page today. Then, create an awesome interactive programming course, submit it before February 28th, and win valuable prizes!

The theme of the contest is PROGRAMMING EDUCATION WITH PYTHON. This is just a general guideline, so use your imagination to create your own unique course. You can build any course as long as it’s educational and involves programming with Python! The rules, possible course ideas, registration form, detailed instructions, tutorials and other helpful materials are all there on the contest page.

The process is pretty simple:

  1. Register on the contest page today. We won’t publish your entry details anywhere, but we will use them for two things: to send you a reminder a few days before the end of the contest, and to check-out your course from the registered repository.
  2. Create an interactive programming course with Python and PyCharm Educational Edition. Recommended topics, rules, instructions and tutorials can be found here.
  3. Place your course in the public Git repository you entered during registration.
  4. Contest ends 23:59, February 28th—that’s the final deadline. That’s when we’ll collect all courses from all repositories for assessment and scoring. The scoring criterias are described in the Rules section on the contest page.
  5. Finally, the winners will be announced March 5th!

That’s it! Dive in now and get your entries in before February 28th!

Best of luck, and most importantly, have fun!
- PyCharm Team

Posted in Conferences & Events | Leave a comment

Design a Python Programming Course and Win!

The JetBrains PyCharm team is thrilled today to announce the start of the Interactive Programming with Python educational contest!


This is a great chance for teachers and instructors all around the globe to show their experience and skills in creating a programming course that thousands of learners will use.
The theme of the contest is PROGRAMMING EDUCATION WITH PYTHON. This is just a general guideline, so use your imagination to create your own unique course. You can build a basic introductory Python programming course, a bioinformatics algorithms course, an advanced data mining course, or anything else—as long as it’s educational and involves programming with Python. Get your creative juices flowing, develop the best interactive course, and compete for valuable prizes!

First, register in the contest, either as a team or an individual. You’ll have about 2 months to develop your programming course and submit your entry. Entries will be judged on a range of criteria accessible to different educational approaches and topics, so don’t be afraid to dive in!
In addition to being a fun competition, this contest is meant to encourage people to start teaching and learning programming using Python and PyCharm. Anyone who feels like creating an exciting and useful interactive programming course can and should take part!
As a known supporter of different educational programs, JetBrains is sponsoring this contest with valuable prizes. For more details on the conditions, rules and prizes please see the contest webpage, where you can also submit your entry.

Best of luck, and have fun!

Posted in Conferences & Events | Tagged , | 1 Comment

Announcing the PyCharm 4.0.4 release update

As the first week of the New Year 2015 is almost gone, PyCharm team is excited to present the first PyCharm update of this year – PyCharm 4.0.4 build 139.1001.

This update contains a lot of improvements: IPython Notebook integration, the debugger, the embedded local terminal, Git and Subversion support, resolve of class references, Lettuce support, CSS support – all this have got our attention.

Also there is one small but handy feature. If you open a Python console tool window and would like to have more then one consoles there, now there is a special button just for that:


The full list of all the fixes and improvements is available in the release notes.

As usual, please report any problem you have to our issue tracker.

If you would like to discuss your experiences with PyCharm, we look forward to your feedback on our PyCharm Facebook page and twitter.

Develop with Pleasure!
-PyCharm team

Posted in Release Announcements | 6 Comments