O'Reilly Forums: Help! Stuck On Chapter 2/ Page 39 :( - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Help! Stuck On Chapter 2/ Page 39 :(

#1 User is offline   ravi84 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 04-March 12

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 thumbnail(s)

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

0

#2 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 306
  • Joined: 20-August 09

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.

--Paul.
0

#3 User is offline   ravi84 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 04-March 12

Posted 05 March 2012 - 01:41 PM

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


Regards,
Ravi
0

#4 User is offline   ravi84 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 04-March 12

Posted 06 March 2012 - 12:05 PM

Just an extension to my original question:

In Page 41, where the notes says:

Quote

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)

Regards,
Ravi

This post has been edited by ravi84: 06 March 2012 - 12:06 PM

0

#5 User is offline   memilanuk 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 33
  • Joined: 28-October 09

Posted 07 March 2012 - 08:57 AM

http://askubuntu.com...in-the-terminal

http://askubuntu.com...open-a-terminal
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users