List Info

Thread: Re: help on raw_input()




Re: help on raw_input()
country flaguser name
United Kingdom
2007-04-14 07:49:05
"ammar azif" <ceasar102yahoo.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.0rnHost: somehostrnrn'

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://ww
w.freenetpages.co.uk/hp/alan.gauld 


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

Re: help on raw_input()
country flaguser name
Malaysia
2007-04-14 07:59:10
Thanks the encode method really helps.

Alan Gauld <alan.gauldbtinternet.com> wrote:
"ammar azif" 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.0rnHost: somehostrnrn'

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 - Tutorpython.org
http://mail.python.org/mailman/listinfo/tutor
yahoo.com>


Ahhh...imagining that irresistible "new car" smell?
Check out new cars at Yahoo! Autos.
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )