March 13, 2008

Web2py’s interactive shell in iPython

Filed under: dev, python, web2py — michaelangela @ 7:51 am

This shell for web2py is quite cool. (You can look here for a Google tranlation of the original.) For those new to this stuff (like me), and if you’re working on something specific you can specify that in the environment. If you want to play with your model straight away, and it’s named ‘db’, you can add

environment[‘db’]=__import__(‘applications.%s.models.db’ % app, fromlist=[‘*’])

Just a convenience thing for testing.

As I worked with it, I wanted to load it into iPython. My very poor way is I have a small script to just load the environment.

# file:web2pyshell.py
from shell import *
app=raw_input(‘app to load environment for:’)
for k,v in env(app).items(): locals()[k]=v

# in ipythonrc add
execute sys.path.append(‘C:\\path\\to\\web2py’)
execute os.chdir(‘C:\\path\\to\\web2py’)
execfile web2pyshell.py

so when I load up iPython, it’s all loaded up and waiting to go. Very very nice.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: