ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
Re: [Tutor] Brain In Vice: Why is this so fun to me?
by Liam Clarke other posts by this author
Apr 19 2006 4:32PM messages near this date
[Tutor] Brain In Vice: Why is this so fun to me? | Re: [Tutor] Brain In Vice: Why is this so fun to me?
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@[...].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@[...].org
>  http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Doug Shawhan
Liam Clarke
Liam Clarke
Alan Gauld

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved