string contains and special characters

Dave Angel d at davea.name
Tue Oct 9 10:23:42 EDT 2012


On 10/09/2012 10:02 AM, loial wrote:
> I am trying to match a string that containing the "<" and ">" characters, using the string contains function, but it never seems to find the lines containing the string
>
> e.g if mystring.contains("<TAG>") :
>
> Do I need to escape the characters...and if so how?
>

What language are you trying to use, and what version of that language? 
In all the Python versions I know of, that line would simply be a syntax
error.  There's no "contains" method in the str class, use the 'in' keyword.

    if  "<TAG>' in mystring:

No need to escape any ASCII characters except backslash.

-- 

DaveA




More information about the Python-list mailing list