By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,103 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

need help with my append syntax

P: n/a
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.findNextSibling('td')
addr.append('%s;')

thanks

yaffa

Aug 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
yaffa wrote:
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.findNextSibling('td')
addr.append('%s;')


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.spreadfirefox.com/?q=affiliates&amp;id=67907&amp;t=1>
Aug 12 '05 #2

P: n/a
On 12 Aug 2005 09:31:08 -0700
"yaffa" <ya*********@gmail.com> wrote:
addr = incident.findNextSibling('td')
addr.append('%s;')


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
Aug 12 '05 #3

P: n/a
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:
sorry addr is a variable. how to i append to that?
I know addr is a variable (or better a name). But what object do you
assign to it? I mean, does incident.findNextSibling('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.

----- Original Message ----- From: "Qiangning Hong" <ho****@gmail.com>
To: "yaffa" <ya*********@gmail.com>
Cc: <py*********@python.org>
Sent: Friday, August 12, 2005 12:47 PM
Subject: Re: need help with my append syntax

yaffa wrote:
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.findNextSibling('td')
addr.append('%s;')

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.spreadfirefox.com/?q=affiliates&amp;id=67907&amp;t=1>

--
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.spreadfirefox.com/?q=affiliates&amp;id=67907&amp;t=1>
Aug 12 '05 #4

P: n/a
yaffa wrote:
dear folks,
Dear Yaffa,
i'm trying to append a semicolon to my addr string
Python strings don't have a 'append' method.
and am using the
syntax below. for some reason the added on of the ; doesn't work.
"doesn't work" is the worst possible description of a problem.
Please read
http://www.catb.org/~esr/faqs/smart-questions.html
when i print it out later on it only shows the original value of addr.

addr = incident.findNextSibling('td')
addr.append('%s;')
If you don't have an AttributeError here then addr is not bound to a string.
thanks

yaffa

--
bruno desthuilliers
ruby -e "print 'o****@xiludom.gro'.split('@').collect{|p|
p.split('.').collect{|w| w.reverse}.join('.')}.join('@')"
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Aug 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.