[Tutor] help on raw_input()

Alan Gauld alan.gauld at btinternet.com
Sat Apr 14 14:49:05 CEST 2007


"ammar azif" <ceasar102 at yahoo.com> wrote

> Actually i wanted to write a http client using just he low level 
> socket module.

I won;t ask why! But the httplib module probably does what you want
just in case you dodn't realize it existed...

> The program will prompt the user asking for input and the
> use will type http commands like
> 'GET /index.html HTTP/1.0\r\nHost: somehost\r\n\r\n'

OK, So you want the user to acrtually type \,n,\,n and you
will then send that string to be interpreted as newlines?

> when i use the raw_input function , the string that i get is
> 'GET /index.html HTTP/1.0\\r\\nHost: somehost\\r\\n\\r\\n'

The double \\ doesn''t actually exist its just Python telling you
that it is a literal \ character not an escaped sequence.
As I said earlier if you check the len() of the string it will
only have one character per backslash.

I think it's already doing what you want!
You just need to turn the \n's that the user entered into
newline characters, Kent has shown you how to do that
with the decode() method...

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list