[Tutor] abs beginner first project

Alan Gauld alan.gauld at freenet.co.uk
Wed Jul 12 20:37:01 CEST 2006


>> I'm thinking about text editor.

> GUIs aren't the most Pythonic thing you could find to write.

Text editor != GUI

Many of the most interesting text editors are not GUI bsased
and in fact there is a gap(IMHO) at the moment for a really good batch
oriented text editor(*) - sed is OK but it is really stream based,
not batch. So a really nice batch oriented text editor would
be a potentially useful tool.

Now a beginner won't write a killer batch editor first time out
but it sure would be an interesting starter project and potentially
easy to add features later.

(*)By batch oriented I mean the ability to edit a text filke by
loading a set of prewritten editing commands, these can then
be applied to a whole set of files from a shell loop say.

Of course you could write a Python program to do this or
an elisp function for emacs etc. But a true batch oriented
editor (as used to be found on mainframe and midi computers
- Think EDT on VAX; except it had inrteractive mode too)

You invoke it like:

$ myeditor -dfilename=foobar.py myfile.txt mycommands.cmd

and mycommands .cmd looks something like:

g25                            # go line 25
s/mystring/otherstring/   # replace string
df/startRE/finishRE/     # delete from start to finish
g+7                            # move down 7 lines
3w                             # move in 3 words
i$filename                   # insert the value of filename (defined 
in the commandline
x                               # save and exit

That's in vi like pseudo code but hopefully gives an idea. Its
easy enough to make up your own, maybe an SGML style.
EDT used words like:

LINE 25
SUBSTR mystring newstrinhg
DELETE FROM mystring TO endstring
etc...

You can of course include loops and subroutines/macros too.

The value of this as a beginner project is that no display magic
needs to happen, simple status messages are enough...

> For example, in Tkinter, you can bind buttons to function calls, but 
> you can't have buttons pass arguments to the functions.  So you have 
> to somehow make a separate function for each button, or do some 
> weird backend event handling stuff that you can look up

Its almost trivially simple to do that. I wouldn't think it would
deter too many beginners. (ie a lambda calling a function providing
the arguments needed)

> interested.  Point is, you don't want to be hindered by having to 
> figure out stuff like that when you're just learning how to use a 
> new language.

But the basic point is well made, you don't want to be learning
new frameworks when you are really trying to learn core python.

> Or were you suggesting a console-based text editor?

Console based is possible, either in line mode like ex, ed
or in screen mode like vi, or in batch mode as discussed above.
You could even use page mode like ISPF on MVS, so far as I
know there are no page mode editors on Wondows/Unix, it
might be an interesting challenge! (OTOH hand there is a
good reason there are no page mode editors oin those OS! :-)

Alan G 




More information about the Tutor mailing list