dear folks,
i have the following lines of python code:
couch = incident.findNextSibling('td')
price = couch.findNextSibling('td')
sdate = price.findNextSibling('td')
city = sdate.findNextSibling('td')
strUrl = addr.b.string
currently what this ends up doing is creating something like this
couch3201/01/2004newyork
now what i want to do is add a semicolon after the couch, price, sdate,
city so that i get something like this
couch;32;01/01/2004;new york
does anyone know how to do this?
thanks
yaffa
p.s. i tried couch = couch + ';' and then i tried couch = couch + ";"
and then i tried couch = couch.append ';' 4 1922
On 2005-08-13, yaffa <ya*********@gmail.com> wrote: i have the following lines of python code:
couch = incident.findNextSibling('td') price = couch.findNextSibling('td') sdate = price.findNextSibling('td') city = sdate.findNextSibling('td') strUrl = addr.b.string currently what this ends up doing is creating something like this
couch3201/01/2004newyork
now what i want to do is add a semicolon after the couch, price, sdate, city so that i get something like this
couch;32;01/01/2004;new york
Try this:
s = ';'.join([couch,price,sdate,city])
print s
p.s. i tried couch = couch + ';' and then i tried couch = couch + ";"
both of those should have worked fine.
and then i tried couch = couch.append ';'
1) The append() method of a sequence doesn't return anything.
2) You call methods using ()
3) String are immutable, and therefore don't have an append
method.
Perhaps you ought to read through the tutorial?
--
Grant Edwards grante Yow! LOOK!!! I'm WALKING
at in my SLEEP again!!
visi.com
On 13 Aug 2005 08:14:32 -0700, "yaffa" <ya*********@gmail.com> wrote: dear folks,
i have the following lines of python code:
couch = incident.findNextSibling('td') price = couch.findNextSibling('td') sdate = price.findNextSibling('td') city = sdate.findNextSibling('td') strUrl = addr.b.string currently what this ends up doing is creating something like this
couch3201/01/2004newyork
now what i want to do is add a semicolon after the couch, price, sdate, city so that i get something like this
couch;32;01/01/2004;new york
does anyone know how to do this?
thanks
yaffa
p.s. i tried couch = couch + ';' and then i tried couch = couch + ";" and then i tried couch = couch.append ';'
Assuming all your findNextSibling calls result in strings, as in couch = 'couch' price = '32' sdate = '01/01/2004' city = 'newyork'
You can put them in a list [couch, price, sdate, city]
['couch', '32', '01/01/2004', 'newyork']
And join them with a string inserted between each successive pair of elements
';'.join([couch, price, sdate, city])
'couch;32;01/01/2004;newyork'
If you like a space after each ';', just include it in the joiner string
'; '.join([couch, price, sdate, city])
'couch; 32; 01/01/2004; newyork'
If all your items weren't string type, you'll have to convert first, e.g., price = 32 '; '.join([couch, price, sdate, city])
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: sequence item 1: expected string, int found '; '.join(map(str,[couch, price, sdate, city]))
'couch; 32; 01/01/2004; newyork'
If you have 2.4 and don't like map, you can use a generator expression:
'; '.join(str(x) for x in (couch, price, sdate, city))
'couch; 32; 01/01/2004; newyork'
or if you want the quoted strings
'; '.join(repr(x) for x in (couch, price, sdate, city))
"'couch'; 32; '01/01/2004'; 'newyork'"
Note: if you want ';' appended to each item instead of just between items, you
can just add ';' to the whole thing
'; '.join(str(x) for x in (couch, price, sdate, city)) + ';'
'couch; 32; 01/01/2004; newyork;'
Which avoids the trailing blank you would get if you appended '; ' to every item
before joining them, as in
''.join(('%s; '%x) for x in (couch, price, sdate, city))
'couch; 32; 01/01/2004; newyork; '
or
''.join((str(x) + '; ') for x in (couch, price, sdate, city))
'couch; 32; 01/01/2004; newyork; '
HTH
Regards,
Bengt Richter
Grant Edwards wrote: On 2005-08-13, yaffa <ya*********@gmail.com> wrote:
i have the following lines of python code:
couch = incident.findNextSibling('td') price = couch.findNextSibling('td') sdate = price.findNextSibling('td') city = sdate.findNextSibling('td') strUrl = addr.b.string currently what this ends up doing is creating something like this
couch3201/01/2004newyork
now what i want to do is add a semicolon after the couch, price, sdate, city so that i get something like this
couch;32;01/01/2004;new york
Try this:
s = ';'.join([couch,price,sdate,city]) print s
I'll risk myself with something like:
s = ';'.join([tag.string for tag in [couch,price,sdate,city]])
Of course, from the question I wouldn't have any clue. I just like doing
some guessing on problems I know nothing about. ;) p.s. i tried couch = couch + ';' and then i tried couch = couch + ";"
both of those should have worked fine.
Not really. It seems to me the OP is using BeautifulSoup (or some other
SGML parser). In this case, couch and others are not strings but objects.
It may also be that strUrl is their parent (but I wouldn't know, how
would I?)
Perhaps you ought to read through the tutorial?
That's always useful.
However, the first thing is to put the minimal context in your question
to help the people you want your answers from understanding your issue.
I would advise you to read tutorials and documentations on the modules
you're using as well as learning to ask meaningful questions[1].
[1] http://www.catb.org/~esr/faqs/smart-questions.html
On 2005-08-13, tiissa <ti****@nonfree.fr> wrote: Grant Edwards wrote:
s = ';'.join([couch,price,sdate,city]) print s
I'll risk myself with something like:
s = ';'.join([tag.string for tag in [couch,price,sdate,city]])
Of course, from the question I wouldn't have any clue. I just like doing some guessing on problems I know nothing about. ;)
p.s. i tried couch = couch + ';' and then i tried couch = couch + ";"
both of those should have worked fine.
Not really. It seems to me the OP is using BeautifulSoup (or some other SGML parser). In this case, couch and others are not strings but objects.
Seems like a reasonable guess.
It may also be that strUrl is their parent (but I wouldn't know, how would I?)
Nope. :)
--
Grant Edwards grante Yow! Are you mentally here
at at Pizza Hut??
visi.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: yaffa |
last post by:
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...
|
by: Prashanth Badabagni |
last post by:
Hi,
Can any body tell me how to print "hello,world" with out using semicolon
Thanks in advance ..
Bye
Prashanth Badabagni
|
by: Dan |
last post by:
I'm writing a record from an asp.net page to SQL Server. After the insert
I'm selecting @@identity to return the ID of the record that I just wrote.
It worked fine until I typed a semicolon into...
|
by: Simon |
last post by:
Hi folks,
I'm aware of the fact that using a StringBuilder is more efficient than
constantly reassigning a string. For example.
Example A
---------
SringBuilder sb = new StringBuilder();...
|
by: Sandro Dentella |
last post by:
I'd like to understand why += operator raises an error while .append() does
not. My wild guess is the parses treats them differently but I cannot
understand why this depends on scope of the...
|
by: Lawrence San |
last post by:
According to a JavaScript debugger (Firebug), and to a JS lint, this is
fine:
function recalc(){deriv = 6;}
But, if I've assigned the function to a variable like this:
var bells =...
|
by: Peter Michaux |
last post by:
Hi,
These first three links say that when reading document.cookie the
name-value pairs are separated by semicolons and they show examples
like "name=value;expires=date" where there is clearly...
|
by: pythonnoob |
last post by:
Hello everyone. New to python as well as this forum, but i must say ive learned a but already reading through some posts. Seems to be a pretty helpful community here.
Before i post a question...
|
by: bashhead |
last post by:
Hi all,
I have a basic shell script question.
Say I have a variable called test.
I already have a value in test = 'monkey'
How do I append another value taken from a file, to this variable?...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |