Need better string methods

benjamin schollnick bscholln at mac.com
Sun Mar 7 14:55:55 EST 2004


In article <0d4k40987t6d70bahqil3geth640bufgoc at 4ax.com>, David MacQuigg
<dmq at gain.com> wrote:

> The resistance will come from people who throw at us little bits and
> pieces of code that can be done more easily in their chosen CPL.
> String processing, for example, is one area where we may face some
> difficulty.  Here is a typical line of garbage from a statefile
> revision control system (simplified to eliminate some items that pose
> no new challenges):
> 
> line = "..../bgref/stats.stf| SPICE | 3.2.7  | John    Anderson  \n"
> 
> The problem is to break this into its component parts, and eliminate
> spaces and other gradoo.  The cleaned-up list should look like:
> 
> ['/bgref/stats.stf', 'SPICE', '3.2.7', 'John Anderson']
> 
> # Ruby:
> # clean = line.chomp.strip('.').squeeze.split(/\s*\|\s*/)
> 
> This is pretty straight-forward once you know what each of the methods
> do.
> 
> # Current best Python:
> clean = [' '.join(t.split()).strip('.') for t in line.split('|')]
> 
> This is too much to expect of a non-programmer, even one who
> undestands the methods.  The usability problems are 1) the three
> variations in syntax ( methods, a list comprehension, and what *looks
> like* a join function prefixed by some odd punctuation), and 2) The
> order in which each step is entered at the keyboard.  ( I can show
> this in step-by-step detail if anyone doesn't understand what I mean.)
> 3) Proper placement of parens can be confusing.

David,

   I think your coming at this too much like a programmer...  |-)

   Your right, this is tooo complex for a non-programmer to expect
to simply use...

   So redefine the problem, or look at it from a 90 degree angle.

   If making the users understand the syntax is to complex, than
redefine the syntax.

   Define a set of commands, and make them function wrappers around
your code.

> line = "..../bgref/stats.stf| SPICE | 3.2.7  | John    Anderson  \n"

   I am assuming your running into these lines on a regular basis, so
make a wrapper around your python function...  Call it "Cleanup" or
"Parse_bar_line_string" or something that makes sense to your
users, and have them call that function....

         - Benjamin



More information about the Python-list mailing list