[Tutor] help on raw_input()

ammar azif ceasar102 at yahoo.com
Sat Apr 14 14:59:10 CEST 2007


Thanks the encode method really helps.

Alan Gauld <alan.gauld at btinternet.com> wrote: "ammar azif"  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 


_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070414/51fb17f2/attachment.html 


More information about the Tutor mailing list