Problems with range

Discussion in 'Python' started by Adrian Albisser, Jun 26, 2004.

  1. 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.
     
    Adrian Albisser, Jun 26, 2004
    #1
    1. Advertising

  2. Adrian Albisser

    Chris Share Guest

    On Fri, 25 Jun 2004 19:06:39 -0400, Adrian Albisser <> wrote:
    > 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
     
    Chris Share, Jun 26, 2004
    #2
    1. Advertising

  3. httplib.HTTPResponse question

    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.

    --
    Christopher Baus
    http://www.baus.net/
    Tahoe, Wine, and Linux.
     
    Christopher Baus, Jun 26, 2004
    #3
  4. Re: httplib.HTTPResponse question

    > 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()
     
    Christopher Baus, Jun 26, 2004
    #4
  5. Adrian Albisser

    Tyler Eaves Guest

    On Fri, 25 Jun 2004 19:06:39 -0400, Adrian Albisser wrote:

    > 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).
     
    Tyler Eaves, Jun 26, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    46
    Views:
    1,000
    Antoon Pardon
    Jul 25, 2006
  2. Lambda
    Replies:
    2
    Views:
    425
    James Kanze
    Jul 16, 2008
  3. Tomoyuki Kosimizu

    Range does not take an Range object.

    Tomoyuki Kosimizu, Nov 25, 2003, in forum: Ruby
    Replies:
    3
    Views:
    171
    Tomoyuki Kosimizu
    Nov 27, 2003
  4. David Bird
    Replies:
    1
    Views:
    245
    Tiago Macedo
    Jun 23, 2008
  5. Joey Zhou
    Replies:
    5
    Views:
    250
    Joey Zhou
    Apr 15, 2011
Loading...

Share This Page