4 ms·
This might be completely trivial, but can someone explain to me how one Python idiom is not to mix tabs and spaces, and another is to align arguments over sever
by kmfrk 15y ago
This might be completely trivial, but can someone explain to me how one Python idiom is not to mix tabs and spaces, and another is to align arguments over several lines when needed like this:
def __init__(self, first, second, third,
fourth, fifth, sixth):
I see similar examples elsewhere, and I don't see how you can achieve the alignment without mixing in spaces - at least in some cases. I, too, prefer to align arguments, but it looks bad in places like GitHub and Pastebin, when my Sublime Tex-written code gets uploaded.
Am I missing something here? The two just seem mutually exclusive in most cases (where the alignment position's required spaces % 4 != 0. Is the indentation done with just spaces then?
- sam 15y agoYes, indentation is done just with spaces. Tabs are not used. Typically you set your text editor to have the tab key print 4 spaces.
- kmfrk 15y agoAh, there lies the rub. Thanks a bunch.
- xtacy 15y agoEDIT: Emacs is pretty intelligent when it comes to indenting Python code; it does not merely insert 4 spaces for a TAB, but it automatically aligns your code to the Python expression in your previous line! I don't know which one is the "right" way, but I certainly prefer Emacs's default behaviour. Maybe I just didn't configure my Vim properly :-) Example: In Emacs: def _five(one,two, ....,,,,..three,four): In Vim, with 4 space Tabs: def _five(one,two, ....,,,,|hree,four): | => cursor position when you press ENTER.