Forum Archive

Pythonista indent vs Tab

donnieh

If I am editing a Pythonista file (.py) in Xcode, what key on my Mac is used to properly indent?

When I use Tab on the Mac keyboard I get an error at run time. When I copy and paste the Pythonista indent it runs.

I thought the indent was tab?

ccc

Hit the spacebar four times.

dgelessus

Depends on what you've been using in Pyhonista as the indentation method. Compare the indentation settings of Xcode and Pythonista and make sure that they are the same.

donnieh

4 space bar hits does the same thing...

alt text

donnieh

Pythonista is set to "2 Spaces". Here are my Xcode settings, what should I change? When I set Xcode indent to 2 spaces it still has an error. Hmmm

alt text

dgelessus

Does your Pythonista use soft tabs (n spaces) or hard tabs (the actual tab character, as in "\t")? That needs to be configured in Xcode as well (first dropdown menu on the settings screen you posted).

ccc

In Pythonista, Settings, Indentation, turn on both Soft Tabs and Show Mixed Indentation as they will save you a lot of grief on the iOS side.

In Pythonista, Settings, (you might have to scroll down) Action Menu, turn on Convert Indentation.... Then open the file in question and select Convert Indentation from the Action Menu (the wrench icon).

Read the first few links at http://google.com/search?q=tabnanny

On the Mac side, run Applications/Utilities/Terminal and cd into the directory where your Python files are and then type python -m tabnanny -v . (that final period is important) to see where your indentation issues are. Use the spacebar, (not the tab key) to fix up the offending lines by deleting all leading whitespace and then pressing the spacebar until the text is where you think it should be. Rerun tabnanny.