Jump to content


Help! Stuck On Chapter 2/ Page 39 :(

  • Please log in to reply
4 replies to this topic

#1 ravi84


    New Member

  • Members
  • Pip
  • 3 posts

Posted 04 March 2012 - 04:35 PM

After learning about Functions in Chapter 1, I have moved on to Chapter 2, where, in Page 39, I am hoping to create a nesster.py file and CALL it in IDLE, rather than copy paste the text.
I seem to have difficulty understanding this step:
"Rather than typing your function’s code into IDLE’s prompt, bring the nester.py file into IDLE’s edit window,
and then press F5 to run the module’s code:"

I used the File-> Open from my IDLE and located my .py file.
This opened my Function in a new IDLE window. From the new Window, when I hit on Run -> Run Module, I see a "Expected and Indented Block" error message..!

Though I am using different names for my .py files and also different variable names inside my function, I am fairly confident that I used the right indentation and have no where else to go.
Request you all to please look into the attachment and suggest what changes to make.

Thank you so much in advance!!

Attached Thumbnails

  • Screenshot at 2012-03-04 18:32:23.png

#2 paulbarry


    Advanced Member

  • O'Reilly Author
  • PipPipPipPipPipPipPipPip
  • 307 posts

Posted 05 March 2012 - 06:37 AM

The problem you are having has to do with the way Python treats indentation in your code. Python uses whitespace to denote indentation... and this means that SPACE and TAB can be used (but not interchangeable). If you mix SPACE and TAB in your code the Python interpreter can get confused because it counts the whitespace to work out the level of indentation. This means that code that looks OK to you (visually) will break with an IndentError when Python sees it. One TAB character is one level of indentation, whereas four SPACEs (which looks the same as one TAB to me and you) is *four* levels of indentation... remember: Python counts your whitespace.

To fix this, use IDLE to untabify your code. Choose Edit... Select All..., then choose Format... Untabify Region... from the menus. Set the tab width to 4 when prompted.

I've found that it's a good idea to adjust your editor to always replace a press of the TAB key with four SPACEs when working with Python code. This gets rid of this type of thing reoccurring.

Hope this helps.


#3 ravi84


    New Member

  • Members
  • Pip
  • 3 posts

Posted 05 March 2012 - 01:41 PM

That worked !! Thanks a lot for taking out some time and explaining in detail.


#4 ravi84


    New Member

  • Members
  • Pip
  • 3 posts

Posted 06 March 2012 - 12:05 PM

Just an extension to my original question:

In Page 41, where the notes says:

Open a terminal window within your nester folder and type a single command: python3 setup.py sdist

I have learnt that I am supposed to SHIFT+Right Click on the Folder that contains my .py files and choose "Open Command Prompt".

This did work in Wndows 7 for me.
Can some one brief on whether there is another better way to do it AND/OR how to do it on a Linux Operating System? (Ubuntu 11.10)


Edited by ravi84, 06 March 2012 - 12:06 PM.

#5 memilanuk


    Active Member

  • Members
  • PipPip
  • 33 posts

Posted 07 March 2012 - 08:57 AM



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users