How to get TabError?

M

Mr. Magoo

Can someone provide a snippet which, when run, generates a TabError?

I can only seem to get SyntaxError and IndentationError.

Thanks,
M
 
J

Jeff Epler

When running with "-tt", you can get this error.

[jepler@sofa src]$ python -tt
Python 2.3.3 (#1, May 7 2004, 10:31:40)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 3
b
^
TabError: inconsistent use of tabs and spaces in indentation


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCRt7EJd01MZaTXX0RAuXQAKCCI6hsv29qK9bNFZrk9dayihCT7wCfSZMm
LosXa6miRGuwE5s4y470r3Y=
=y0vY
-----END PGP SIGNATURE-----
 
F

Fredrik Lundh

Mr. Magoo said:
Can someone provide a snippet which, when run, generates a TabError?

I can only seem to get SyntaxError and IndentationError.

$ python -c "print repr(open('test.py').read())"
'if 1:\n\tprint "hello"\n print "goodbye"\n'

$ python test.py
hello
goodbye

$ python -t test.py
test.py: inconsistent use of tabs and spaces in indentation
hello
goodbye

$ python -tt test.py
File "test.py", line 3
print "goodbye"
^
TabError: inconsistent use of tabs and spaces in indentation

</F>
 
M

Mr. Magoo

"Fredrik Lundh said:
$ python -c "print repr(open('test.py').read())"
'if 1:\n\tprint "hello"\n print "goodbye"\n'

$ python test.py
hello
goodbye

$ python -t test.py
test.py: inconsistent use of tabs and spaces in indentation
hello
goodbye

$ python -tt test.py
File "test.py", line 3
print "goodbye"
^
TabError: inconsistent use of tabs and spaces in indentation

</F>


Thanks.

Is there a reason (good or otherwise :) why py_compile dumps this and
IndentationError in a different format than SyntaxError?

M
 
M

Mr. Magoo

"Fredrik Lundh said:
$ python -t test.py
test.py: inconsistent use of tabs and spaces in indentation
hello
goodbye

On more question. When using py_compile from with a script, is there any
way to force the -t flag?

M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,228
Messages
2,571,157
Members
47,785
Latest member
deepusaini

Latest Threads

Top