Python "Edit" Modules

edit is a Python module for use with the MacPython Integrated Development Environment (IDE). It allows you to type

>>> edit(foo)
and an appropriate editor will be launched for foo, depending on its datatype. If foo is a string, a dialog box will pop up allowing you to edit the string in the proper Mac way; if it's a Numeric matrix, a spreadsheet-like matrix editor will appear; if it's nothing that can be so nicely edited, you'll at least get Just's cool object browser.

The edit system is modular and extendable; particular editors are stored in separate modules, but all accessed via one edit module (which knows how to locate and call the others as appropriate).


edit is brand new, born on Feb. 24, 1999. It's quite likely that the interfaces (both user and API) will change as I get feedback from other users and continue to develop it myself. I'm posting it now simply to get that feedback, so please have a look and let me know how it suits your needs.


Grab the files below, and put them somewhere in your Python path, all in the same folder: helper module for (preliminary but cool!) main edit module (import this!) editor for 2D Numeric arrays editor for Python sequences (not yet implemented) if all else fails, launches the object browser editor for short strings


Using edit is simple: start by importing two functions...
from edit import edit, editreturn
Then, to edit some data 'foo', type "edit(foo)" to edit it in place (without returning the edited data), or "editreturn(foo)" to edit and return the new value.

Why the second function? It's needed for immutable types like strings. These can't be edited in place, so you'll need to do something like this:

foo = "bar"
foo = editreturn(foo)
But most other datatypes are mutable, so you can just say "edit(foo)" and be done with it.

Defining New Editors

Creating a new edit module is equally simple:
  1. Your module name must start with "edit" (e.g., "").

  2. Your module must define a "canedit(data)" function, which examines data and returns a number between 0 and 10. These numbers have meaning roughly as follows:
    0can't do anything with this data
    1can display but not edit this data
    2can crudely edit this data
    5can reasonably edit this data
    8can edit this data quite well
    10ideal editor for this specific data

  3. Your module must define an "edit(data,returndata)" function which edits data. It should always return the edited data; the 'returndata' is provided for your information -- for example, if you're given an immutable datatype and returndata is 0 (meaning that it will not be returned to the user), your function should print a warning.
That's all there is to it! Have a look at the editors included above to see how easy it is. I hope to have a nice collection of editors for a wide variety of datatypes, so if you have something to contribute, please send it in.
Last Updated: 2/24/99 . . . . . .