By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,630 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,630 IT Pros & Developers. It's quick & easy.

Picking apart strings

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.