Saturday, February 18, 2012

Tabs and Indentation

Setting Up Your Text Editor

Indentation (whitespace (spaces and tabs) before text) is very important in Python.  It helps define where blocks of code begin and end.  For the purposes of this blog, we're going to need to set up your text editor.

I'm going to show you how to change your tab settings in both Notepad++ (Windows) and TextWrangler (Mac).  If you are using a different editor, don't panic.  Doing this is very common and a quick Google search should show you how to do it in your editor.

Notepad++

Open Notepad++ and go to "Settings" on the menu and click "Preferences."



On the window that appears go to the tab labelled "Language Menu/Tab Settings."



Under the "Tab Settings" frame, make sure "[Default]" is selected.  In the lower right corner, check the box that says "Replace by space" and then set the "Tab size" to 2.



Click close and you're ready to go!


Text Wrangler

Text Wrangler is a bit more tricky, but it's still easy enough.  With Text Wrangler open, go to the "Preferences" entry under the "TextWrangler" menu.



A window like this will appear.



On the left, click on the line called "Editor Defaults."



Now, check the box next to "Auto-expand tabs."



Now go down to "Default font:" and click on "Set..."


A box like this should appear.



Set the "Tab Width" to 2 spaces


Now close that window and the Preferences window and you're all set.


Why?

Why did we just go through all that?  You'll see in the next lesson (Lesson 5)!








No comments:

Post a Comment