Re: Text conversion in python

From: Anthony Valentine <amv@akvalentine.com>
Date: Wed Mar 23 2005 - 19:01:33 AKST

Thanks, I'll give that a try.

Anthony

Mac Mason wrote:

>Regular expressions in python are slightly less handy than in perl, because
>they're implemented as a module, not as a built-in.
>The following should do the trick:
>
> >>> text = "This is a \'test\'"
> >>> print text
> This is a 'test'
> >>> import re
> >>> text2 = re.sub("\'", "", text)
> >>> print text2
> This is a test
>
>re is the regular expression module.
>Note that regular expression patterns are input as strings, unlike perl; this
>means you have to escape a lot more things. (Like that single-quote)
>
>For the whole shebang, have a look at
><http://www.python.org/doc/2.4/lib/module-re.html>
>
> --Mac
>
>On Thu, Mar 24, 2005 at 04:32:52PM -0900, Adam bultman wrote:
>
>
>>Anthony Valentine wrote:
>>
>>
>>
>>>Hello everyone!
>>>
>>>I am very new to python and cannot seem to figure out how to perform a
>>>simple text substitution.
>>>
>>>I want to remove all single quotes from a line of text.
>>>
>>>In perl, I would use:
>>> $var =~ s/'//g;
>>>
>>>Does anyone know how to do this in python?
>>>
>>>Thanks in advance!
>>>
>>>Anthony Valentine
>>>
>>>
>>>
>>>
>>>
>>>
>>I don't know python, but you might try escaping that single-quote?
>>
>>Adam
>>
>>
>>
>>
>>>---------
>>>To unsubscribe, send email to <aklug-request@aklug.org>
>>>with 'unsubscribe' in the message body.
>>>
>>>
>>>
>>>
>>>
>>---------
>>To unsubscribe, send email to <aklug-request@aklug.org>
>>with 'unsubscribe' in the message body.
>>
>>
>>
>
>
>

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Thu Mar 24 17:55:47 2005

This archive was generated by hypermail 2.1.8 : Thu Mar 24 2005 - 17:55:47 AKST