[Newbie] Is the text delimiter changeable?

Chris Liechti cliechti at gmx.net
Sun Jun 30 12:02:26 EDT 2002


baf at texas.net (Ben Fairbank) wrote in news:3d1f26a4.5915886 at news.texas.net:

> I have to process large amounts of text and the text includes numerous
> apostrophes and quotation marks.  It would be very handy if I could
> temporarily assign a substitute for Python's use of the caracters "
> and ' to delimit text strings.  If I could use, for example, the @
> character or the # character, neither of which appears in the text I
> have to work with, and if I could disable the " and ' delimiters, then
> my task would be greatly simplified.  I realize I can backslash escape
> these characters in some circumstances, but I do not think that will
> work when a user's input is a word such as "can't" or "don't."
> Anyway, short of doing something truly drastic, such as recompiling
> the system (which I have no intention of doing), is there a workaround
> that will permit this?

are these text you wan't to process python sources in any way or just 
normal text? in the later you can load these texts in python strings and 
there you can have any character without having a special effect.

e.g. to replace all "is" in a text with "isn't":
out = file("output.txt","w")
for line in file("input.txt"):
    	out.write(line.replace("is", "isn't")) #process lines

HTH
chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list