[Tutor] help on raw_input()

ammar azif ceasar102 at yahoo.com
Sat Apr 14 09:46:43 CEST 2007


Actually i wanted to write a http client using just he low level socket module.
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'
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'

is there any easy way other than modify this string ? Perhaps regular expression?



Alan Gauld <alan.gauld at btinternet.com> wrote: "ammar azif"  wrote

> i wanted to get a string from raw_input like this
> 
> raw_input('>')
>> \n\nsomestring

OK, Can you explain precisely what you want the string to contain.
\n is the string representation of a newline. Do you want to enter 
something that starts with two newlines? Or do you literally want
the sequence \,n,\,n?

If its the latter thats what Python has stored. The double slash 
is only there when python displays the result (Try using len and 
comparing if you aren't convinced)

If you want to actually capture newline characters from raw_input, 
thats more tricky. But before we get to that can you clarify what 
you actually want?

Alan G.

_______________________________________________
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/0884abef/attachment.html 


More information about the Tutor mailing list