Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

a re problem

1 view
Skip to first unread message

cheng

unread,
May 20, 2005, 10:05:29 AM5/20/05
to
>>> p.sub('','a\nbc')
'abc'
>>> p.sub('','%s') % "a\nbc"
'a\nbc'

is it anyone got some idea why it happen?

Mikael Olofsson

unread,
May 20, 2005, 10:23:53 AM5/20/05
to cheng, pytho...@python.org

cheng wrote:

>>>p.sub('','%s') % "a\nbc"
>>>
>>>
>'a\nbc'
>
>is it anyone got some idea why it happen?
>

Make that

p.sub('','%s' % "a\nbc")


Regards
/Mikael Olofsson

Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE])
Linköpings universitet

-----------------------------------------------------------------------
E-Mail: mik...@isy.liu.se
WWW: http://www.dtr.isy.liu.se/en/staff/mikael
Phone: +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
-----------------------------------------------------------------------
Linköpings kammarkör: www.kammarkoren.com Vi söker tenorer och basar!

Fredrik Lundh

unread,
May 20, 2005, 10:21:43 AM5/20/05
to pytho...@python.org
"cheng" <magi...@spymac.com> wrote:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'p' is not defined

>>> import re
>>> p = re.compile("\n*")


>>> p.sub("", "a\nbc")
'abc'
>>> p.sub("", "%s")

'%s'

</F>

cheng

unread,
May 20, 2005, 10:28:49 AM5/20/05
to
thx for help :)

Message has been deleted

James Stroud

unread,
May 28, 2005, 2:09:28 PM5/28/05
to pytho...@python.org

py> import re
py> target = 'blah'
py> text = 'yaddah blah yaddah yaddah'
py> ext = re.sub(r'\b%s\b' % target,'',text)
py> ext
'yaddah yaddah yaddah'


On Friday 27 May 2005 10:56 pm, cheng wrote:
> hi,all, i try to replace every target word found in the text
>
> for target in splitText:
> if stopwords.find(target) >= 0 :
> text = re.sub(r'\b%s\b','',text) &target
>
> when i using the statment:
>
> text = re.sub(r'\b%s\b','',text) &target
>
> get error : unsupported operand type(s) for &: 'str' and 'str'
>
> is it some idea that can modity it and make it work?

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/

0 new messages