Flask Snippets

Preconfigured interactive shell

Posted by Dag Odenhall on 2010-05-28 @ 07:00 and filed in Utilities

The documentation recommends putting imports in a module and import that when you're in an interactive session. Even better, I think, is to make an executable that launches a preconfigured Python shell.

Put something like this in for example shell.py and run chmod +x shell.py.

#!/usr/bin/env python

import os
import readline
from pprint import pprint

from flask import *

from myapp import *
from utils import *
from db import *
from models import *

os.environ['PYTHONINSPECT'] = 'True'

Normally import * should be avoided but unless you get namespace collisions it makes sense for an interactive shell environment.

Now you can simply do ./shell.py.

This snippet by Dag Odenhall can be used freely for anything you like. Consider it public domain.