Converting = to ==

William Park parkw at
Thu Apr 27 17:16:14 EDT 2000

On Thu, Apr 27, 2000 at 03:57:55PM -0400, Warren Postma wrote:
> 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

You can use regular expression '([^=])=([^=])', but I think your
solution is cleaner.


More information about the Python-list mailing list