Thursday, March 26, 2009

Python Tabs

I use tabs, real tabs, and only tabs for indenting.

If I download code I convert it, I hate spaces.

I write my code in windows, I use PSPad, I always have View | Special Chars enabled, so my code looks like this:



def filetolist(filename, clean = True):
->result = []
->f = open(filename, 'r')
->for line in f.xreadlines():
->->removedn = False
->->if clean:
->->->stripped = line.strip()
->->->if len(stripped) > 0:
->->->->result.append(stripped)
->->->#end if
->->else:
->->->if len(line) > 0 and line.endswith('\n'):
->->->->line = line[:-1] # remove 1 char
->->->->removedn = True
->->->#end if
->->->result.append(line)
->->#end if
->#end for
->if not clean and removedn:
->->result.append('')
->#end if
->return result
#end def



The only reason I use tabs, and hate spaces with a passion because every now and then I find myself editing a .py file in a text editor that does not support "smart" tabs, and when I used to spaces, it was the most tedious thing in the world to work on that .py file. Now when I find myself using a "dumb" editor, like notepad, or nano, the tabs are HUGE, and thats fine because I'll take the clarity of seeing my code blocks AND being able to manipulate code much quicker by tabbing quickly to my indentation points as opposed to holding down the space bar, and then deleting the few extra spaces I had put in any day.

And guess what, every "smart" text editor out there can support and display tabs any way you like, so you don't even have to know you're using them.

I know I should get off PSPad and start using a real Python editor, but I haven't had the time to focus on it, and I don't like doing anything half assed, so when I research my IDEs I want the best one for me.

I use PyLint, its brilliant. Its a pain to get going on windows but worth it.

Pylint scores my code very low, a negative number out of 10! But I'm not a fan of its default style, so I'm happy with that.

I run pylint -e filename.py it can't find all errors that are normally found at compile time but it does a very impressive job.

No comments: