Problems with range

A

Adrian Albisser

Hey to everybody, im just beginning to program in python. So i was trying
some function but always when i try the range function i get a error
message.

for number in range(1,100):
print number

Error---> There's an error in your program:
expected an indented block

I tried many examples i found at different tutorials but i always get the
error.
 
C

Chris Share

Hey to everybody, im just beginning to program in python. So i was trying
some function but always when i try the range function i get a error
message.

for number in range(1,100):
print number

Error---> There's an error in your program:
expected an indented block

Read what the message tells you. The problem is not with your range
function, it's the rest of the program. In Python, indenting is
important; it tells the interpreter which bits go together.

So your program should be:
for number in range(1,100):
print number

Note the 4 spaces at the start of the second line. It doesn't have to be
4 spaces, but that's convention.

I'd suggest you read a good python tutorial - I like
http://www.freenetpages.co.uk/hp/alan.gauld/tutintro.htm

And of course there's http://www.python.org/doc/current/tut/ on the
python site itself.

chris
 
C

Christopher Baus

Hi all,

I'm writing an HTTP client test package in python to test my C++ proxy
server (http://www.summitsage.com/). For this reason I want to construct
the (malformed) HTTP requests myself, but use httplib to parse the
server's response. I don't see an easy way to do this. I suspect I could
construct the response on the socket and have it read the response, but
this is undocumented.

Any suggestions?

tia.
 
C

Christopher Baus

I'm writing an HTTP client test package in python to test my C++ proxy
server (http://www.summitsage.com/). For this reason I want to construct
the (malformed) HTTP requests myself, but use httplib to parse the
server's response. I don't see an easy way to do this. I suspect I could
construct the response on the socket and have it read the response, but
this is undocumented.

To answer my own question. This isn't documented in the standard python
docs, but it is seems to work:

response = httplib.HTTPResponse(sock)
response.begin()
print response.read()
 
T

Tyler Eaves

Hey to everybody, im just beginning to program in python. So i was trying
some function but always when i try the range function i get a error
message.

for number in range(1,100):
print number

Try:


for number in range(1,100):
print number
^^
Note the intention.

Basically, any time you have a line ending in :, you'll need to indent
the following line (and maybe more).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top