need help with my append syntax

Y

yaffa

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
 
Q

Qiangning Hong

yaffa said:
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>
 
M

Michael Ekstrand

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
 
Q

Qiangning Hong

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.
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" <[email protected]>
To: "yaffa" <[email protected]>
Cc: <[email protected]>
Sent: Friday, August 12, 2005 12:47 PM
Subject: Re: need help with my append syntax


--
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>
 
B

bruno modulix

yaffa said:
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 '(e-mail address removed)'.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 '(e-mail address removed)'.split('@')])"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top