473,289 Members | 1,917 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,289 software developers and data experts.

Picking apart strings

Is there a way to pick apart this text without resorting to regular
expressions?

p {
color: black;
}

p -element
color -property
black -value
Jun 27 '08 #1
2 1298
On Jun 3, 1:44 pm, tmallen <thomasmal...@gmail.comwrote:
Is there a way to pick apart this text without resorting to regular
expressions?

p {
color: black;

}

p -element
color -property
black -value
http://code.google.com/p/cssutils/

Jun 27 '08 #2
On Jun 3, 11:44 am, tmallen <thomasmal...@gmail.comwrote:
Is there a way to pick apart this text without resorting to regular
expressions?

p {
color: black;

}

p -element
color -property
black -value
Sure.

data = txt.strip("}").split("{")

element = data[0].strip()

items = data[1].split(";")

for item in items:

data = item.split(":")
property = data[0].strip() # avoid this keyword
value = data[1].strip()

I didn't test this. Also, the module suggested in the other reply
might make more sense, depending on how much of this sort of thing you
need to do.
Jun 27 '08 #3

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

Similar topics

9
by: Bart Nessux | last post by:
I am using method 'a' below to pick 25 names from a pool of 225. A co-worker is using method 'b' by running it 25 times and throwing out the winning name (names are associated with numbers) after...
115
by: J | last post by:
I've run CSSCheck on my style sheets and I always get a warning similar to this: "font: bold 9pt/100% sans-serif Warning: Absolute length units should not generally be used on the Web ..." ...
2
by: Erik Max Francis | last post by:
I was interesting in adding selection and hit testing to ZOE, and was looking at the PyOpenGL wrappers' handling of selection and picking. I see glSelectBuffer to specify the size of the buffer,...
1
by: Adam Clauss | last post by:
I have a few variables that I want declared as global. To accomplish this, I made the files globals.h and globals.cpp. In globals.h I have the declarations for the structs, and one variable...
1
by: rcamarda | last post by:
I have a column that has text delimited by a percent sign that I wish to turn into rows. Example: A column contains ROBERT%CAMARDA, I want to turn that into two rows, one row with ROBERT and...
8
by: Notgiven | last post by:
Say you have two dates, 2005-01-01 and 2005-01-24. I want to get a list or array or all the date between and including those two dates. I want to include this list in a query so I need it in a...
7
by: noridotjabi | last post by:
I'm working on a prompt style thing and I need a way to pass arguments to commands within my program. For example: ::hello -v -r -n If this is entered as one input string, can I (in any...
7
by: smohideen | last post by:
I have a known problem of GLIBCXX version mismatch while running my binary compiled on Fedora 5 on Fedora 3. It says "version `GLIBCXX_3.4.5' not found " . Then I did GLIBCXX_3.4 GLIBCXX_3.4.1...
2
by: Semajthewise | last post by:
Ok guys, This is a quick overview of what I'm trying to do. 2 textboxes. textbox1 has a fraction entered by the user into it in one of these 2 ways 1(space)3/4 or simply 3/4 Now what this code is...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.