Re: quoting strings



Michal Duda wrote:

> is any equivalent to perl "quotemeta" function in python?

s = re.escape(s)

> I know that I can use this on string: r'\\test'
> but I need to do this on the variable

your example is a string literal, which isn't really the same thing as
a RE pattern in Python.

</F>



.



Relevant Pages

  • Re: dictionary/hash and 1 versus 1
    ... In order to keep things simple, Perl's string operators ... programming language you have to use its idioms or you end up fighting ... IMO, since Python is strongly but dynamically typed, a) is the 'worst' ... Perl and Python. ...
    (comp.lang.python)
  • TOC of Python Cookbook now online (was Re: author index for Python Cookbook 2?)
    ... Processing a String One Character at a Time ... Finding a File on the Python Search Path ... Constructing Lists with List Comprehensions ... Looping over Items and Their Indices in a Sequence ...
    (comp.lang.python)
  • Re: =?ISO-8859-15?Q?Objektrepr=E4sentation_in_einem_Python?= =?ISO-8859-15?Q?-In
    ... Python 1.4 hat zwar ein uniformes Typsystem, Exemplare sind aber nur nur eine Art von Python-Objekt, will sagen, nicht jedes Ding hat eine Klasse. ... Called when an attribute lookup has not found the attribute in the usual places (i.e. it is not an instance attribute nor is it found in the class tree for self). ... Das einzige Element von None könnte null sein, Integer und String sind klar. ...
    (de.comp.lang.java)
  • Re: =?ISO-8859-15?Q?Objektrepr=E4sentation_in_einem_Python?= =?ISO-8859-15?Q?-In
    ... Exemplare von Klassen. ... Einzig vom Anwender definierte Klassen können Exemplare haben. ... wirklichen Grund sich an die Hierarchie von Python halten zu müssen. ... Wenn ich es richtig verstanden habe, dann ist es in Python möglich einem String eine neue Funktion zu geben, vielleicht sogar eine alte zu ersetzen. ...
    (de.comp.lang.java)
  • Re: Unrecognized escape sequences in string literals
    ... the string literal doesn't change this basic truth. ... are left in the string unchanged, i.e., the backslash ... expect that if Python had always behaved the way that C++ ... It's a legal escape sequence that maps to ...
    (comp.lang.python)