471,330 Members | 1,178 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

replace characters in a string

hi!

i want to replace these characters:
Expand|Select|Wrap|Line Numbers
  1. sex_m-designer_bw-size_42
so that i have the argument string:
Expand|Select|Wrap|Line Numbers
  1. sex=m&designer=bw&size=42 
i am working under zope 3.
glad for any help you can give me (i am veryyyy new in python, so please speak slow).

thank you,
steven, vienna
Oct 11 '07 #1
2 25028
bartonc
6,596 Expert 4TB
hi!

i want to replace these characters:
Expand|Select|Wrap|Line Numbers
  1. sex_m-designer_bw-size_42
so that i have the argument string:
Expand|Select|Wrap|Line Numbers
  1. sex=m&designer=bw&size=42 
i am working under zope 3.
glad for any help you can give me (i am veryyyy new in python, so please speak slow).

thank you,
steven, vienna
Here, again, the replace() method of a string object will do the job nicely:
Expand|Select|Wrap|Line Numbers
  1. >>> s = "sex_m-designer_bw-size_42"
  2. >>> s = s.replace('_', '=')
  3. >>> s = s.replace('-', '&')
  4. >>> s
  5. 'sex=m&designer=bw&size=42'
  6. >>> 
Here, I have used Python's interactive interpreter (denoted by the '>>>' prompt) to run off a quick test of the idea. In interactive mode, all of the built-in types (most of which are true objects in the OOP sense of the term) and functions are available.

Hope I spoke slowly enough,
Barton
Oct 11 '07 #2
Barton,

you are the man!

you saved my day!
(and kept the doctor away)

hurray.
Oct 11 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Locusta | last post: by
3 posts views Thread by JPSutor | last post: by
4 posts views Thread by jpierson | last post: by
11 posts views Thread by jarod1701 | last post: by
reply views Thread by rosydwin | last post: by

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.