473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

split string problems

Hey. I am trying to grab the prices from the string below but I get a
few errors when I try to do it: Take a look at the code and error
messages below for me and thanks you in advanced to all that help.
Thank you. Here's the code & error messages:
>>p
[<span class="sale">
$14.99
</span>, <span class="sale">
$27.99
</span>, <span class="sale">
$66.99
</span>, <span class="sale">
$129.99
</span>, <span class="sale">
$254.99
</span>]
>>p.split()[2]
Traceback (most recent call last):
File "<pyshell#11>", line 1, in -toplevel-
p.split()[2]
AttributeError: 'ResultSet' object has no attribute 'split'
>>>
Sep 7 '06 #1
3 2769
try str(p).split()[2]

your class is using the __str__ attribute to print and I am guessing
that is what you are seeing.

Tempo wrote:
Hey. I am trying to grab the prices from the string below but I get a
few errors when I try to do it: Take a look at the code and error
messages below for me and thanks you in advanced to all that help.
Thank you. Here's the code & error messages:
>p
[<span class="sale">
$14.99
</span>, <span class="sale">
$27.99
</span>, <span class="sale">
$66.99
</span>, <span class="sale">
$129.99
</span>, <span class="sale">
$254.99
</span>]
>p.split()[2]

Traceback (most recent call last):
File "<pyshell#11>", line 1, in -toplevel-
p.split()[2]
AttributeError: 'ResultSet' object has no attribute 'split'
>>
Sep 7 '06 #2
On Thu, 2006-09-07 at 16:21 -0700, Tempo wrote:
[<span class="sale">
$14.99
</span>, <span class="sale">
$27.99
</span>, <span class="sale">
$66.99
</span>, <span class="sale">
$129.99
</span>, <span class="sale">
$254.99
</span>]
Worked alright for me (see below). Are you sure "p" is a string ?

Cut and paste from interactive python shell:
>>p = """
.... [<span class="sale">
.... $14.99
.... </span>, <span class="sale">
.... $27.99
.... </span>, <span class="sale">
.... $66.99
.... </span>, <span class="sale">
.... $129.99
.... </span>, <span class="sale">
.... $254.99
.... </span>]"""
>>p.split()
['[<span', 'class="sale">', '$14.99', '</span>,', '<span',
'class="sale">', '$27.99', '</span>,', '<span', 'class="sale">',
'$66.99', '</span>,', '<span', 'class="sale">', '$129.99', '</span>,',
'<span', 'class="sale">', '$254.99', '</span>]']
>>p.split()[2]
'$14.99'
>>>
Regards,

John
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Sep 8 '06 #3
Tempo wrote:
Hey. I am trying to grab the prices from the string below but I get a
few errors when I try to do it: Take a look at the code and error
messages below for me and thanks you in advanced to all that help.
Thank you. Here's the code & error messages:
>>>p
[<span class="sale">
$14.99
</span>, <span class="sale">
$27.99
</span>, <span class="sale">
$66.99
</span>, <span class="sale">
$129.99
</span>, <span class="sale">
$254.99
</span>]
>>>p.split()[2]

Traceback (most recent call last):
File "<pyshell#11>", line 1, in -toplevel-
p.split()[2]
AttributeError: 'ResultSet' object has no attribute 'split'
The contents of p is rather "odd" looking. It isn't html that
was read from a website (note the commas after </span>). You
show it as if it is a list of strings, but the strings don't
have quotes around them. How are you creating the object p?
If you would just get it into a single string (with something
like:

x=urllib.urlopen(url)
p=x.read()

then you can use elementree, or beautiful soup to get your
prices quite easily.

-Larry
Sep 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Xah Lee | last post by:
Python Doc Problem Example Quote from: http://docs.python.org/lib/module-os.path.html ---------- split( path) Split the pathname path into a pair, (head, tail) where tail is the last...
5
by: MDB | last post by:
Hello all, I have having problems figuring out how to split on a string rather than a char. Any help would be appreciated. Here is what I am trying to do. string...
3
by: Andi Twine | last post by:
Hi all, I really hope someone here can help ! I have designed and built an ASP.NET web service with Visual Studio .NET. The web service outputs some dummy XML data when its called with some...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
10
by: pantagruel | last post by:
Hi, I'm looking for an optimal javascript function to split a camelcase string and return an array. I suppose one could loop through the string, check if character is uppercase and start...
4
by: Steven D'Aprano | last post by:
I'm having problems passing a default value to the maxsplit argument of str.split. I'm trying to write a function which acts as a wrapper to split, something like this: def mysplit(S, sep=None,...
1
Atli
by: Atli | last post by:
The following small HowTo is a compilation of an original problem in getting some cookie-values through different methods of string-handling. The original Problem was posted as follows: As...
10
by: vunet.us | last post by:
Hello, I use XMLHTTP to get an HTML of another page. Then, I need to cut some middle part of that HTML string but I have problems doing it (see note in caps below). The error I have generated at...
2
by: Transcend2030 | last post by:
Hi, I'm having problems with string.split() My problem is; I have a sentence which the user inputs, I then input a word and the number of times that word appears in the sentence is displayed. ...
3
by: Dave | last post by:
I'm calling string.Split() producing output string. I need direct access to its enumerator, but would greatly prefer an enumerator strings and not object types (as my parsing is unsafe casting...
0
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$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.