a re problem

Discussion in 'Python' started by cheng, May 20, 2005.

  1. cheng

    cheng Guest

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

    'a\nbc'

    is it anyone got some idea why it happen?
     
    cheng, May 20, 2005
    #1
    1. Advertising

  2. "cheng" <> wrote:

    > >>> p.sub('','a\nbc')

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

    > 'a\nbc'
    >
    > is it anyone got some idea why it happen?


    >>> p.sub('', 'a\nbc')

    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>
     
    Fredrik Lundh, May 20, 2005
    #2
    1. Advertising

  3. 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:
    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!
     
    Mikael Olofsson, May 20, 2005
    #3
  4. cheng

    cheng Guest

    thx for help :)
     
    cheng, May 20, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Suurkuusk
    Replies:
    0
    Views:
    3,981
    Andreas Suurkuusk
    Jul 27, 2003
  2. Ted Miller
    Replies:
    0
    Views:
    5,155
    Ted Miller
    Sep 13, 2003
  3. Merek
    Replies:
    0
    Views:
    1,964
    Merek
    Dec 3, 2003
  4. Scott Meddows
    Replies:
    1
    Views:
    391
    John Saunders
    Jun 8, 2004
  5. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    550
    Bullschmidt
    May 11, 2004
Loading...

Share This Page