Syntax Highlighting in Terminal for Python?

4

Is there a way to turn on python syntax highlighting for Terminal.app on Mac OS X?

Alex

Posted 2010-03-31T03:00:42.390

Reputation:

2Do you mean inside the Python read-eval-print interpreter? – Lawrence Velázquez – 2010-03-31T05:38:28.603

Answers

7

If you just want to highlight sources you dump into the terminal a la cat try excellent pygments. It actually supports a lot of languages. Run with

pygmentize source.py

If instead you were talking about editing files with syntax highlighting inside a mac terminal, this really depends on the editor.

  • for vi or vim you want at least these option in ~/.vimrc

    syntax on
    
  • emacs works right out of the box

  • don't ask me about nano.

Benjamin Bannier

Posted 2010-03-31T03:00:42.390

Reputation: 13 999

include "/usr/share/nano/python.nanorc" - quite good. – user1686 – 2010-03-31T18:18:03.450

1

Try ipython. It highlights syntax and much more.
I haven't tried it on Mac but looks like it must work:
https://stackoverflow.com/questions/726449/installing-ipython-with-readline-on-the-mac

Another option is WxPython and pycrust (which works without Terminal.app :( )

Alex Bolotov

Posted 2010-03-31T03:00:42.390

Reputation: 1 284

0

You can try ptpython in github, simply

pip install ptpython

and use it with ptpython.

zyy

Posted 2010-03-31T03:00:42.390

Reputation: 117

0

Here is a series of screencasts, that shows bpython in action:

http://bpython-interpreter.org/screenshots/

iElectric

Posted 2010-03-31T03:00:42.390

Reputation: 339

It's gone now, however, and returns a 404, supporting @Diogo's point. – martin-martin – 2019-10-19T01:50:11.667

1While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Diogo – 2012-08-09T12:45:41.750

@Diogo, visiting the site will show that this link is to how-to videos. It's difficult to include essential parts in that respect. I agree that the answer needs work, but I don't think your comment is helpful. – None – 2012-08-12T05:41:46.153

No problem Randolph, this comment was automatically posted by the review system when I reviewed it. – Diogo – 2012-08-12T14:19:10.013