[Tutor] Brain In Vice: Why is this so fun to me?
Liam Clarke
ml.cyresse at gmail.com
Thu Apr 20 01:32:02 CEST 2006
Hi Doug,
Best tip ever is your_python_dir\tools\scripts\redemo.py
Interactive regexes. :)
This is pretty good as well - http://www.amk.ca/python/howto/regex/
Good luck,
Liam Clarke
On 4/20/06, doug shawhan <doug.shawhan at gmail.com> wrote:
> I think I'm going to have to suck it up and learn some regular expressions.
>
> I have finally gotten my script (using the excellent pyserial module) to
> behave. Most of my troubles as enumerated here before were utterly
> self-induced. Apparently one cannot watch the execution of one's script
> through another program without affecting it's outcome in unforseen ways.
> (Sound familiar Herr Schroedinger? :-)
>
> Now that I am actually extracting data in a fairly predictable way, I am at
> the point where I need to parse it! I have some output here (modified to
> show the ESC and NUL characters.)
>
> When I pull data from the port, the remote computer sends it in one long
> string per screen: newlines are not painted in by using the expected x\0a
> that I had hoped for! No easy readlines() fun for me. Instead I get:
>
> ESC=( 1. ESC=($4x2, 6-239 (3.9L)
> ..........................................ESC=(a03252
> ESC=(k0
> ESC=) 2. ESC=))8-318 (5.2L)
> ..........................................ESC=)a03242
> ESC=)k0
> ESC=* 3. ESC=*)8-360 (5.9L)
> ..........................................ESC=*a03351
> ESC=*k 0
> ESC=+ 4. ESC=+$4x4, 6-239 (3.9L)
> ..........................................ESC=+a03240
> ESC=+k 0
> ESC=, 5. ESC=,)8-318 (5.2L)
> ..........................................ESC=,a03243
> ESC=,k 0
> ESC=- 6. ESC=-)8-360 (5.9L)
> ..........................................ESC=-a03352
> ESC=-k 0
> ESC=. 7. ESC=.aCH8299 ESCTNULESC)NULESC=% LINEESCTNULESC=& R =
> RELIST <return> = NONE
>
> I have broken it up for ease of viewing. I need to split the string where
> ESC= , k and 0 are found, but ESC= ,k and 0 are seperated by various
> spaces, parentheis and other characters that are apparently used to mark the
> end of the line until the next ESC is found, thereby displaying a new line
> (note how the character after the first ESC on each line is repeated after
> the ESC on the end.
>
> I cannot for the life of me figure out a pythonic way (read: using the
> split() builtin) to scan for instances of these characters in such and such
> order and proximity. I know this is what regex is for, but I have no
> experience. I have obtained a copy of "Mastering Regular Expressions" but
> thought I would inquire here first for caveats and tips as the book is
> larger than my brain, and I haven't used the re module, ever.
>
> Why in the world does this make me so happy? :-)~
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
More information about the Tutor
mailing list