The Artima Developer Community
Sponsored Link

Python Buzz Forum
Inspector Python (in praise of shell)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
maxim khesin

Posts: 251
Nickname: xamdam
Registered: Mar, 2005

Maxim Khesin is developer for Liquidnet. I like C++, python, attend design patterns study group/NYC.
Inspector Python (in praise of shell) Posted: Feb 27, 2006 9:50 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by maxim khesin.
Original Post: Inspector Python (in praise of shell)
Feed Title: python and the web
Feed URL: http://feeds.feedburner.com/PythonAndTheWeb
Feed Description: blog dedicated to python and the networks we live in
Latest Python Buzz Posts
Latest Python Buzz Posts by maxim khesin
Latest Posts From python and the web

Advertisement
The importance of Python's interactive shell has been pointed out before, so I just want to add some drops to the sea.

The interactive shell feature was one of the first pointed out in Guido's talk at Google last week. People coming from static language background (mea culpa) should realize that working in the shell is not just some extra bolt-on, it is really a modus operandi for many serious Python (or other REPL language, but I will talk of Python) programmers.

In Python shell, you do not 'create' a program , not until *after* you developed it! You really 'live' in the program, work with live objects, introspect them and the docs, and take some notes for later so you can save your thougts. Unfortunately the integration between shell mode and program mode is not so great in the editors I've used, so you end up just pasting chunks of code around. (I have once seen an editor that claimed better integration, but I forgot what it was).

Beside working with objects a lot of what I do in a shell is looking up docs. I use help() a lot, sometimes dir() helps even more. A recent habit I aquired that seems to be paying off nicely is the inspect module. I highly recommend it, as it adresses the same needs as help() and dir() in an arguably superior way. Instead of giving you the docs for a class or function, it can actually give you the entire code. inspect.getsource() is the ticket.

For example, I needed to look up some parameters to django.db.models.Field. The old me would've started searching the docs. But with inspect I just do this:


>>> print inspect.getsource(models.Field.__init__)
def __init__(self, verbose_name=None, name=None, primary_key=False,
maxlength=None, unique=False, blank=False, null=False, db_index=False,
core=False, rel=None, default=NOT_PROVIDED, editable=True,
prepopulate_from=None, unique_for_date=None, unique_for_month=None,
unique_for_year=None, validator_list=None, choices=None, radio_admin=None,
help_text='', db_column=None):
Ain't that nice?

Read: Inspector Python (in praise of shell)

Topic: Gstreamer based python audio player in no time Previous Topic   Next Topic Topic: WSGI is making a real difference

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use