/home/shakir

Interactive Python shell with IPython

Posted on 15 Dec, 2007, categorized under Information Insemination



One nice thing about Python as compared to some other scripting languages, is that it has a shell that enables us to test our Python script on the fly without needing to write a script file first

It’s nice and all that, but when you’re too used to IDEs which has features such as auto completion etcetera, you’ll feel like something is not right about the default python shell.

That changes when I come to IPython, one of the few other enhanced Python shell. The one feature I like most is the auto complete feature, which among other by using it I don’t need to remember module names, and at the same time would list and try Python modules that I’ve never heard of.

In Ubuntu, or debian in general, the package is called ipython, and to install it just;

shakir@herugrim ~ $ sudo apt-get install ipython

Can you spot the differences between this

shakir@herugrim ~ $ python
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import command
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named command
>>> import commands
>>> status, output = commands.getoutputstatus ('ls')
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'getoutputstatus'
>>> status, output = commands.getstatusoutput ('ls')
>>> print output
Desktop
Documents
Music
Photos
>>>
shakir@herugrim ~ $

and this?

shakir@herugrim ~ $ ipython
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
Type "copyright", "credits" or "license" for more information.

IPython 0.8.1 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import command
---------------------------------------------------------------------------
           Traceback (most recent call last)

/home/shakir/ in ()

: No module named command

In [2]: import commands

In [3]: status, output = commands.
commands.__all__           commands.__hash__          commands.__setattr__
commands.__class__         commands.__init__          commands.__str__
commands.__delattr__       commands.__name__          commands.getoutput
commands.__dict__          commands.__new__           commands.getstatus
commands.__doc__           commands.__reduce__        commands.getstatusoutput
commands.__file__          commands.__reduce_ex__     commands.mk2arg
commands.__getattribute__  commands.__repr__          commands.mkarg

In [3]: status, output = commands.gets
commands.getstatus        commands.getstatusoutput

In [3]: status, output = commands.getstatusoutput('ls')

In [4]: print output
Desktop
Documents
Music
Photos

In [5]:
Do you really want to exit ([y]/n)? y
shakir@herugrim ~ $

I hope you can guess when did I press the [tab] key :)

Tags: ,




Looking for something else? Search Google.

No Responses to "Interactive Python shell with IPython"

Comment Form


  • si perda: wah.. boleh kasi need for speed test power skali... boleh layan network race ni...
  • Faiz: wah....harganya berapa?
  • shakir: Hmm, I have no lab and that actually was my living room :D Sure I'll move them to one of my available rooms at home and make it a lab, but that'll be
  • peja: whoaaa..at least u have ur own lab...look interesting!
  • Qing Ru: He looks really cute! Fatherhood must have been quite rewarding :)
  • shakir: Chris: Thanks, I've updated the post.
  • shakir: tak cukup banyak guinea pig yang dah try and comment on the wimax service, and so I'll just wait :D
  • shakir: Vadim: Yup, but I prefer to just install dosbox and play the game rather than re-installing my system with 32 bit Linux :D
  • Vadim: 2shakir: wine doesn't support 64-bit linux. You have to use 32-bit linux if you want to use wine.
  • kevler: yerp ...dalam 2 hari nih jer ..aku dah kesan 2 BMW X6 , kat puchong dan jalan ampang ..giler laa lawa



Disclaimer

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my own personal opinion. Inappropriate comments will be deleted at the authors discretion. All code samples (if any, ever) are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
Personal (Blogs) - TOP.ORG