Sujet : Re: Python (was Re: I did not inhale)
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.unix.shell comp.unix.programmer comp.lang.miscDate : 23. Aug 2024, 01:19:34
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <va8kim$ka4q$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
User-Agent : Pan/0.159 (Vovchansk; )
On Thu, 22 Aug 2024 12:47:16 +0200, David Brown wrote:
On 22/08/2024 11:02, Lawrence D'Oliveiro wrote:
Python prohibits those space/tab inconsistencies.
No, it does not. Python treats tabs (at the start of lines, which is
the only relevant point here) as 8 spaces by default. You can change
that with command-line flags if you want. But it is quite happy with
mixtures of tabs and spaces as long as the result after tab-to-space
conversion is consistent with Python syntax.
src = \
"""
def fun() :
\t\tprint("line 1")
\t\x20\x20\x20\x20\x20\x20\x20\x20print("line 2")
fun()
"""
exec(src)
Output:
TabError: inconsistent use of tabs and spaces in indentation