[Baypiggies] regex puzzle

Aaron Maxwell amax at redsymbol.net
Wed Mar 12 17:40:35 CET 2008


Cool, thanks for clarifying JJ.

On Wednesday 12 March 2008 02:07:19 you wrote:
> I wanted to clarify your statement, "The problem is that search_str is
> a variable of type str, not a raw string."
>
> Look at the following:
> >>> r'foo'
>
> 'foo'
>
> >>> 'foo'
>
> 'foo'
>
> >>> raw_input() # going to type foo
>
> foo
> 'foo'
>
> Whether I use a raw string, a normal string, or raw_input(), what I
> get is a str object.
>
> Now, when I *embed a string into Python source code*, some escaping
> happens.  If I use a raw string, less escaping happens.  If I use
> raw_input(), no escaping happens.  In all cases, what I end up with is
>
> a string.  Look at how the escaping works:
> >>> print 'tab: (\t)'  # \t -> tab
>
> tab: (  )
>
> >>> print r'tab: (\t)'  # \t not converted
>
> tab: (\t)
>
> >>> print raw_input()  # raw_input() != typing a string in Python source
> >>> code
>
> tab: (\t)
> tab: (\t)
>
> What Matt seems to be saying is that the cmd module treats lines per
> the UNIX shell convention and uses shell quoting rules.  That's very
> different from Python quoting.
>
> You still have a problem that you'll need to figure out, but hopefully
> I've cleared up at least one thing ;)
>
> Happy Hacking!
> -jj



-- 
Aaron Maxwell
http://redsymbol.net


More information about the Baypiggies mailing list