Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in Python only
Search
Advanced Search
Forums
Product Launch
Updates
Today's Posts
Member List
Calendar
Home
Forum
Topic
Python
Picking apart strings
Collapse
This topic is closed.
X
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
tmallen
#1
Picking apart strings
Jun 27 '08, 04:27 PM
Is there a way to pick apart this text without resorting to regular
expressions?
p {
color: black;
}
p -element
color -property
black -value
jay graves
#2
Jun 27 '08, 04:27 PM
Re: Picking apart strings
On Jun 3, 1:44 pm, tmallen <thomasmal...@g mail.comwrote:
Is there a way to pick apart this text without resorting to regular
expressions?
>
p {
color: black;
>
}
>
p -element
color -property
black -value
Google Code Archive - Long-term storage for Google Code Project Hosting.
http://code.google.com/p/cssutils/
Comment
Post
Cancel
Russ P.
#3
Jun 27 '08, 04:27 PM
Re: Picking apart strings
On Jun 3, 11:44 am, tmallen <thomasmal...@g mail.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.
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment