Hidden Features of Python

Hidden features of PyCharm

As the lead developer of PyCharm, I can tell you that we don't usually hide features in random places, and there are a few reliable ways to discover most of them.

  • Try Ctrl-clicking on everything (methods, functions, template tag names and parameters, etc.)
  • If Ctrl-clicking works, usually so does completion (Ctrl-Space), rename (Shift-F6) and Find Usages (Alt-F7)
  • Look through the menus and try out the actions that seem interesting
  • Look at Settings | Inspections to configure the warnings which can be highlighted by PyCharm, and note that many of the inspections have quickfixes to correct the problems automatically
  • Read the blog and try out the features highlighted there.

Defining private module functions in python

In Python, "privacy" depends on "consenting adults'" levels of agreement - you can't force it (any more than you can in real life;-). A single leading underscore means you're not supposed to access it "from the outside" -- two leading underscores (w/o trailing underscores) carry the message even more forcefully... but, in the end, it still depends on social convention and consensus: Python's introspection is forceful enough that you can't handcuff every other programmer in the world to respect your wishes.

((Btw, though it's a closely held secret, much the same holds for C++: with most compilers, a simple #define private public line before #includeing your .h file is all it takes for wily coders to make hash of your "privacy"...!-))

Hidden features of Groovy?

Using the spread-dot operator

def animals = ['ant', 'buffalo', 'canary', 'dog']
assert animals.size() == 4
assert animals*.size() == [3, 7, 6, 3]

This is a shortcut for animals.collect { it.size() }.

Hidden Features of Erlang

The magic commands in the shell. The full list is in the manual, but the ones I use most are:

  • f() - forget all variables
  • f(X) - forget X
  • v(42) - recall result from line 42
  • v(-1) - recall result from previous line
  • e(-1) - reexecute expression on previous line
  • rr(foo) - read record definitions from module foo
  • rr("*/*") - read record definitions from every module in every subdirectory
  • rp(expression) - print full expression with record formating


Related Topics



Leave a reply



Submit