Tabs or spaces? python pep8

As per the title… what are your guys opinion? I’ve always liked tabbed indentation… but apparently I should be using spaces. What works best for you in practice?

cheers…

J

in theory you’re fine with either approach as long as everyone - including your team - sticks to it throughout.
In practice this does not happen. So your enemy isn’t necessarily tabs or spaces but the mix of them.
Most text editors allow you to go from tab to space, but not all support the opposite. So working with spaces may be a bit easier and reliable, especially when someone already started with code using spaces.
With spaces you lose the flexibility of changing tab width to your like - but this is really dangerous, because, again, if you mix it with space, and if you or your text editor changes the tab width, you’re in for trouble.
Advantage of spaces: no matter your editor, you open the code and it shows up as intended without any unknown side-effects.

Cool… thanks for the input Robert…

I’m teaching python to artists for the first time, and while I might have the habit of using tabs I’m wondering if I should be enforcing spaces for this group of newbies

Yeah, I’d go with spaces.

Also if you end up with a mixed file, and you’re using a text editor that will let you do a find replace for ’ ’ characters.
You can fix it by replacing each tab with 8 spaces (at least in python2), this is because the interpreter does that same replacement when it runs the file.
Which is why you can get some really weird looking indentation, that because its a mix of both, that for some insane reason actually runs.

No clue how to fix python3, it counts each tab as a tab.

cool!

I though for a moment there I was teaching ‘tabs’ but just realised that PyCharm automatically treats tabs as four spaces… so all good!

thanks for the input!

I firmly believe that the PEP standard should have called for tabs, but it doesn’t, so you’re better off going with spaces. You will just end up constantly having to reformat other people’s code if you don’t.

A nice fail-safe against the mix is to always display spaces and tabs characters. Most editors support this feature (notepad++, sublime text, pycharm…) and you can see immediately if your file is mixed.
Especially when you are beginning with Maya python, where the script editor uses Tabs.

spaces.

my beef with tabs is you are forced to open it in something that understands tabs. Go to an artists machine without sublime or notepad++ and now you get to use wordpad just to see the file. Spaces shows up exactly how it supposed to. This also goes for some web stuff, there’s no room for (mis)interpretation with spaces.

Spaces! Tabs are always going to be dependent to some degree on setup of the particular editor you are using. Spaces are unambiguous.

I’m a spaceman

We use tabs 3. A somewhat odd choice, but it matches our long-standing C standards. Which I think was the right move. I’d be happy with anything as long as it’s consistent across my co-workers. Although 8 always seemed absurdly wide to me.

Unless you are using a font with non fixed character widths, but in that case you might want to see a pyscitrist about your self harm issues. +1 to spaces for the same reason. Tab 4 here.

Yeah, I understand the logic. We install Notepad++ on all production machines including all artists, producers, etc. so this is a non-issue for us. My fundamental gripe with spaces is that it is a constant where a tab is a variable. When you’re editing python files that have deeply nested looping and conditionals, you are occasionally required to scroll horizontally which is a pain in the ass. You wouldn’t have to do this nearly as much with tabs because you can temporarily or permanently adjust your tab width.

Regardless, spaces is the standard, and that’s what folks should use.

spaces, and 4 spaces == one indent level. Most editors you can setup to work this way when you hit tab. PyCharm does this by defualt, and it is easy to setup editors like atom, sublime or vim to do so as well.

I go for space since that’s what Maya uses natively. PyCharm also uses space.

Sublime uses tab and it’s a tad annoying when you install it in new machines before you realize you have to set its default.

I go for space since that’s what Maya uses natively. PyCharm also uses space.

Sublime uses tab and it’s a tad annoying when you install it in new machines before you realize you have to set its default.

Four spaces, but consistency is the most important thing.

I’ve always liked tabbed indentation… but apparently I should be using spaces.

Go with what you like, then. There’s pro’s and con’s to both.

I personally see less cons by using spaces, but you may disagree. For example, if you post/see something on the web that’s a python code snippet, it’s going to have spaces. All the python IDE’s or editors I’ve used also allow you to indent with 3-4 spaces and behave as though it’s tabbed-indentation. So hitting tab, or shift+tab, acts as you would expect.

Just as long as you don’t mix spaces/tabs together (man, THAT’S ugly).

Yeah bro… I’m going to stick with the PEP standard and use spaces… I suppose I’ve always seen indentation as a tab thing but 4 spaces certainly gives me nice clean indentation. Happy with how PyCharm takes care of this on the fly! I’m not sure any of my students understand the difference anyhow… Artists and logic don’t always work out on first sight.