need help with my append syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yaffa

    #1

    need help with my append syntax

    dear folks,

    i'm trying to append a semicolon to my addr string and am using the
    syntax below. for some reason the added on of the ; doesn't work.
    when i print it out later on it only shows the original value of addr.

    addr = incident.findNe xtSibling('td')
    addr.append('%s ;')

    thanks

    yaffa

  • Qiangning Hong

    #2
    Re: need help with my append syntax

    yaffa wrote:[color=blue]
    > dear folks,
    >
    > i'm trying to append a semicolon to my addr string and am using the
    > syntax below. for some reason the added on of the ; doesn't work.
    > when i print it out later on it only shows the original value of addr.
    >
    > addr = incident.findNe xtSibling('td')
    > addr.append('%s ;')[/color]

    Is addr is really a string? AFAIK, strings havn't an append methond.

    use += to extend strings:

    ..>>> addr = 'abc'
    ..>>> addr += '%s;'
    ..>>> addr
    'abc%s;'

    --
    Qiangning Hong

    I'm usually annoyed by IDEs because, for instance, they don't use VIM
    as an editor. Since I'm hooked to that, all IDEs I've used so far have
    failed to impress me.
    -- Sybren Stuvel @ c.l.python

    Get Firefox!
    <http://www.spreadfiref ox.com/?q=affiliates&a mp;id=67907&amp ;t=1>

    Comment

    • Michael Ekstrand

      #3
      Re: need help with my append syntax

      On 12 Aug 2005 09:31:08 -0700
      "yaffa" <yaffalandis@gm ail.com> wrote:[color=blue]
      > addr = incident.findNe xtSibling('td')
      > addr.append('%s ;')[/color]

      addr += ';'

      or

      addr2 = '%s;' % addr

      Strings, being immutable, do not support appending like lists do. Also,
      the %whatever specifiers are only in effect when used with the string
      formatting operator (%).

      -Michael

      Comment

      • Qiangning Hong

        #4
        Re: need help with my append syntax

        Do not discuss off-list, maybe others will have better solutions to your
        question. And also please do not top-posting, it makes me difficult to
        trim the irrelevant text.

        yaffa wrote:[color=blue]
        > sorry addr is a variable. how to i append to that?[/color]

        I know addr is a variable (or better a name). But what object do you
        assign to it? I mean, does incident.findNe xtSibling('td') return a
        string or an object of another type?

        If your code "addr.append('% s;')" doesn't raise an exception, it is
        pretty sure what assigned to addr is not a string (maybe a list, which
        has an "append" method). You can use "print addr" or "print repr(addr)"
        to determine that.

        [color=blue]
        > ----- Original Message ----- From: "Qiangning Hong" <hongqn@gmail.c om>
        > To: "yaffa" <yaffalandis@gm ail.com>
        > Cc: <python-list@python.org >
        > Sent: Friday, August 12, 2005 12:47 PM
        > Subject: Re: need help with my append syntax
        >
        >[color=green]
        >> yaffa wrote:
        >>[color=darkred]
        >>> dear folks,
        >>>
        >>> i'm trying to append a semicolon to my addr string and am using the
        >>> syntax below. for some reason the added on of the ; doesn't work.
        >>> when i print it out later on it only shows the original value of addr.
        >>>
        >>> addr = incident.findNe xtSibling('td')
        >>> addr.append('%s ;')[/color]
        >>
        >>
        >> Is addr is really a string? AFAIK, strings havn't an append methond.
        >>
        >> use += to extend strings:
        >>
        >> .>>> addr = 'abc'
        >> .>>> addr += '%s;'
        >> .>>> addr
        >> 'abc%s;'
        >>
        >> --
        >> Qiangning Hong
        >>
        >> I'm usually annoyed by IDEs because, for instance, they don't use VIM
        >> as an editor. Since I'm hooked to that, all IDEs I've used so far have
        >> failed to impress me.
        >> -- Sybren Stuvel @ c.l.python
        >>
        >> Get Firefox!
        >> <http://www.spreadfiref ox.com/?q=affiliates&a mp;id=67907&amp ;t=1>
        >>[/color]
        >[/color]


        --
        Qiangning Hong

        I'm usually annoyed by IDEs because, for instance, they don't use VIM
        as an editor. Since I'm hooked to that, all IDEs I've used so far have
        failed to impress me.
        -- Sybren Stuvel @ c.l.python

        Get Firefox!
        <http://www.spreadfiref ox.com/?q=affiliates&a mp;id=67907&amp ;t=1>

        Comment

        • bruno modulix

          #5
          Re: need help with my append syntax

          yaffa wrote:[color=blue]
          > dear folks,[/color]

          Dear Yaffa,
          [color=blue]
          > i'm trying to append a semicolon to my addr string[/color]

          Python strings don't have a 'append' method.
          [color=blue]
          > and am using the
          > syntax below. for some reason the added on of the ; doesn't work.[/color]

          "doesn't work" is the worst possible description of a problem.
          Please read



          [color=blue]
          > when i print it out later on it only shows the original value of addr.
          >
          > addr = incident.findNe xtSibling('td')
          > addr.append('%s ;')[/color]

          If you don't have an AttributeError here then addr is not bound to a string.
          [color=blue]
          > thanks
          >
          > yaffa
          >[/color]


          --
          bruno desthuilliers
          ruby -e "print 'onurb@xiludom. gro'.split('@') .collect{|p|
          p.split('.').co llect{|w| w.reverse}.join ('.')}.join('@' )"
          python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
          p in 'onurb@xiludom. gro'.split('@')])"

          Comment

          Working...