Converting = to ==

Warren Postma embed at geocities.com
Thu Apr 27 15:57:55 EDT 2000


I have an "end user query tool" that uses Python expressions, but I want
comparisons to be able to be written either as A=B or A==B then I want to
compare them using Python's Eval function.

Problem is if you search and replace all = with == then users have to use
the single-equals convention, and some of them will be python programmers,
and will want to use the "non idiot mode" of the query tool.

So i did this, but is there a better way?

    >>> string.replace( string.replace("a=b a==b", "=", "=="), "====","==")
    a==b a==b

Warren








More information about the Python-list mailing list