Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Hidden features of Python (stackoverflow.com)
132 points by niyazpk on Jan 11, 2012 | hide | past | favorite | 7 comments



I already knew mostly everything in it (Time to switch to a new language!) but here's two that I didn't know:

1.

  from __future__ import braces
Use {} to delimit scope!

2.

  try:
      import readline
  except ImportError:
      print "Unable to load readline module."
  else:
      import rlcompleter
      readline.parse_and_bind("tab: complete")

Used to use [tab]-completion in terminal. One could correctly argue that using iPython would be smarter.. but sometime you are working remotely and don't want to get out of the terminal and install, etc.


Make sure you actually try running "from __future__ import braces"


    >>> from __future__ import braces
      File "<stdin>", line 1
    SyntaxError: not a chance


Once you know a language that well, why is time to switch to a new language? Why not leverage that expertise and use it to write (more) great software?


One does not preclude the other. You can both continue leveraging your experience in the mastered language when developing serious stuff and experiment aside with another language to discover new approaches and patterns to solving problems, which you can often reinvest in the mastered language.


most of these features are so hidden, you learn them the first few nights with python




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: