I am trying to add user input using the raw_input function to string url_orig. I am attempting to replace the spaces with +'s to make a 'google search'. the replace function works fine in IDE but not when I excecute the program. Any help will be appreciated

url_orig = 'http://www.google.com/search?hl=en&q='
url_add1 = ''
s.replace(' ', '+')
print s

Recommended Answers

All 2 Replies

I am trying to add user input using the raw_input function to string url_orig. I am attempting to replace the spaces with +'s to make a 'google search'. the replace function works fine in IDE but not when I excecute the program. Any help will be appreciated

url_orig = 'http://www.google.com/search?hl=en&q='
url_add1 = ''
s.replace(' ', '+')
print s

Erm. Do you have a GUI? If so use a text box. If not, then you'll call the function from command line, right? So you can assume they'll enter input at command line. I don't know how to do input otherwise.

I don't see why you want to fiddle with +'s and spaces? The end? Please define your problem more clearly. It would help if you actually, you know, gave us your full code. I have no clue what s is for example.

BTW: unless you pretend you are Opera or Firefox or something, google won't let you perform a search.

Edit: I think I get you. Well you could try:

s = '+'.join((s.split(' ')))

I've never used replace() so I couldn't tell you what's wrong there.

I just tried replace. It works fine for me. I doubt your code worked for you at all, TBH, since you forgot to assign the replacement:
s = s.replace(' ', '+')

Add "Solved" or "Ignore This" to the thread title and in a day or two it will be too far down the list to notice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.