473,785 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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#1 1>", line 1, in -toplevel-
p.split()[2]
AttributeError: 'ResultSet' object has no attribute 'split'
>>>
Sep 7 '06 #1
3 2800
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#1 1>", 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#1 1>", 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.urlope n(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
4041
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 pathname component and head is everything leading up to that. The tail part will never contain a slash; if path ends in a slash, tail will be empty. If there is no slash in path, head will be empty. If
5
4547
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 strMessages=sData.Split("\r\n"); I basically want to split on a new line.
3
2681
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 simple parameters. I have tested the web service on the PC it was written on (Windows XP, IIS 6, .NET 1.1, VS .NET) through the default HTTP / HTML interface with Internet Explorer. All works fine.
3
9670
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... field1...field2...field3...
10
11950
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 building a new word to add to the array but that seems incredibly wasteful. must be some easy way to do it.
4
2513
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, maxsplit=None): pre_processing() result = S.split(sep, maxsplit) post_processing() return result
1
8377
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 you can see, there could have been a problem with the split-method. The following short article handles ways around this possible problem, that we couldn't reproduce, but someone may possibly encounter it too sometimes. If nothing else, the shown...
10
5524
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 response.write (because it does not split) is: Microsoft VBScript runtime error '800a0009' Subscript out of range: '' /get_item.asp, line 55
2
4766
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. Is there a regex expression which will exclude every word except "word" which I entered. So that words.length will actually display the number of "word" in the sentence. Here is some of my code; The ??!word?? is where I'm stuck. Is this a valid...
3
3634
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 from object to string frequently). Basically generics and not its non- generic counterpart. string str1 = "abc: value1 def: value2 ghi: value3"; char delimiterChars = { '\t' }; string tokens = str1.Split(delimiterChars);
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.