[Tutor] RE module is working ?
Steven D'Aprano
steve at pearwood.info
Thu Feb 3 11:43:50 CET 2011
Karim wrote:
>
> Hello,
>
> I am trying to subsitute a '""' pattern in '\"\"' namely escape 2
> consecutives double quotes:
You don't have to escape quotes. Just use the other sort of quote:
>>> print '""'
""
> * *In Python interpreter:*
>
> $ python
> Python 2.7.1rc1 (r271rc1:86455, Nov 16 2010, 21:53:40)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> expression = *' "" '*
No, I'm sorry, that's incorrect -- that gives a syntax error in every
version of Python I know of, including version 2.7:
>>> expression = *' "" '*
File "<stdin>", line 1
expression = *' "" '*
^
SyntaxError: invalid syntax
So what are you really running?
> >>> re.subn(*r'([^\\])?"', r'\1\\"', expression*)
Likewise here. *r'...' is a syntax error, as is expression*)
I don't understand what you are running or why you are getting the
results you are.
> *Indeed what's the matter with RE module!?*
There are asterisks all over your post! Where are they coming from?
What makes you think the problem is with the RE module?
We have a saying in English:
"The poor tradesman blames his tools."
Don't you think it's more likely that the problem is that you are using
the module wrongly?
I don't understand what you are trying to do, so I can't tell you how to
do it. Can you give an example of what you want to start with, and what
you want to end up with? NOT Python code, just literal text, like you
would type into a letter.
E.g. ABC means literally A followed by B followed by C.
\" means literally backslash followed by double-quote
--
Steven
More information about the Tutor
mailing list