By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,236 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,236 IT Pros & Developers. It's quick & easy.

Tabnanny really useful?

P: n/a
Hi, I looked at tabnanny to check
a python source file.

But I didn't find anything, tabnanny
is able to find, what couldn't be found
by compile command.

Or have I missed something?

best regards,
--
Franz Steinhaeusler
Jul 18 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a

"Franz Steinhaeusler" <fr*****************@utanet.at> wrote in message
news:en********************************@4ax.com...
Hi, I looked at tabnanny to check
a python source file.

But I didn't find anything, tabnanny
is able to find, what couldn't be found
by compile command.

Or have I missed something?
Tabnanny is intended to check whether indentation
has mixed tabs and spaces. Files with mixed tabs
and spaces _can_ compile just fine if the editor
that produced them agrees with the compiler about
the number of spaces that a tab occupies.

On the other hand, such files are quite likely to
be messed up almost beyond repair if one tries
to edit them in an editor that treats tabs differently
from the one that produced it.

Files that stick to one or the other can always
be edited and compiled properly. The python
recommendation is to use spaces, but not
everyone agrees with this.

Most modern Python-aware editors handle
the situation reasonably, although you may have
to set parameters.

John Roth
best regards,
--
Franz Steinhaeusler


Jul 18 '05 #2

P: n/a
On Mon, 20 Dec 2004 13:00:39 -0600, "John Roth"
<ne********@jhrothjr.com> wrote:
Tabnanny is intended to check whether indentation
has mixed tabs and spaces. Files with mixed tabs
and spaces _can_ compile just fine if the editor
that produced them agrees with the compiler about
the number of spaces that a tab occupies.


Thanks for your explanation.

I tried an found:
def a():
->print
->.print

where point is a space.

tabnanny here complains and python compile it just fine.
--
Franz Steinhaeusler
Jul 18 '05 #3

P: n/a
Franz Steinhaeusler wrote:
Thanks for your explanation.

I tried an found:
def a():
->print
->.print

where point is a space.

tabnanny here complains and python compile it just fine.


really? that's a syntax error (you cannot change indentation nillywilly
inside a block), and the Python I'm using surely flags this as an error:

$ python -c "print repr(open('franz.py').read())"
'def a():\n\tprint\n\t print\n'

$ python franz.py
File "franz.py", line 3
print
^
SyntaxError: invalid syntax

while tabnanny gives it one thumb up:

$ python -m tabnanny -v franz.py
'franz.py': Clean bill of health.

what Python version are you using?

</F>

Jul 18 '05 #4

P: n/a
On Tue, 21 Dec 2004 10:24:40 +0100, "Fredrik Lundh"
<fr*****@pythonware.com> wrote:
Franz Steinhaeusler wrote:
Thanks for your explanation.

I tried an found:
def a():
->print
->.print

where point is a space.

tabnanny here complains and python compile it just fine.


really? that's a syntax error (you cannot change indentation nillywilly
inside a block), and the Python I'm using surely flags this as an error:

$ python -c "print repr(open('franz.py').read())"
'def a():\n\tprint\n\t print\n'

$ python franz.py
File "franz.py", line 3
print
^
SyntaxError: invalid syntax

while tabnanny gives it one thumb up:

$ python -m tabnanny -v franz.py
'franz.py': Clean bill of health.

what Python version are you using?

</F>


Oh sorry, I meant
def a():
->print
..->print

C:\Python23\Lib>tabnanny.py -v c:\franz.py
'c:\\franz.py': *** Line 3: trouble in tab city! ***
offending line: ' \tprint\n'
indent not equal e.g. at tab size 1

C:\Python23\Lib>python -c "print repr(open('c:/franz.py').read())"
'def a():\n\tprint\n \tprint\n'

C:\Python23\Lib>c:/franz.py

C:\Python23\Lib>
--
Franz Steinhaeusler
Jul 18 '05 #5

P: n/a
Franz Steinhaeusler wrote:
On Tue, 21 Dec 2004 10:24:40 +0100, "Fredrik Lundh"
<fr*****@pythonware.com> wrote:

Franz Steinhaeusler wrote:

Thanks for your explanation.

I tried an found:
def a():
->print
->.print

where point is a space.

tabnanny here complains and python compile it just fine.


really? that's a syntax error (you cannot change indentation nillywilly
inside a block), and the Python I'm using surely flags this as an error:

$ python -c "print repr(open('franz.py').read())"
'def a():\n\tprint\n\t print\n'

$ python franz.py
File "franz.py", line 3
print
^
SyntaxError: invalid syntax

while tabnanny gives it one thumb up:

$ python -m tabnanny -v franz.py
'franz.py': Clean bill of health.

what Python version are you using?

</F>

Oh sorry, I meant
def a():
->print
..->print

C:\Python23\Lib>tabnanny.py -v c:\franz.py
'c:\\franz.py': *** Line 3: trouble in tab city! ***
offending line: ' \tprint\n'
indent not equal e.g. at tab size 1

C:\Python23\Lib>python -c "print repr(open('c:/franz.py').read())"
'def a():\n\tprint\n \tprint\n'

C:\Python23\Lib>c:/franz.py

C:\Python23\Lib>


Well, you've probably answered your own question, then. Do you think
tabnanny is a useful piece of code now? I used it a lot when I first
started using Python, and still run it over code from unknown sources
(no pun intended) from time to time.

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Jul 18 '05 #6

P: n/a
On Tue, 21 Dec 2004 08:36:31 -0500, Steve Holden <st***@holdenweb.com>
wrote:
Franz Steinhaeusler wrote:

[...]

Oh sorry, I meant
def a():
->print
..->print

C:\Python23\Lib>tabnanny.py -v c:\franz.py
'c:\\franz.py': *** Line 3: trouble in tab city! ***
offending line: ' \tprint\n'
indent not equal e.g. at tab size 1

C:\Python23\Lib>python -c "print repr(open('c:/franz.py').read())"
'def a():\n\tprint\n \tprint\n'

C:\Python23\Lib>c:/franz.py

C:\Python23\Lib>
Well, you've probably answered your own question, then. Do you think
tabnanny is a useful piece of code now?


Not really soo useful, because most syntax and also indentation errors
are actually detected by invoking python, i.e. the command compile.
But as combination for this: yes why not.
I looked for Stanis spe editor, which uses a combination of these two.

The background is:

I'm a member of the wxPython project Drpython (Python text editor
and much more), and wanted also check the usefulness of a kind of syntax
check, which should run, before saving a Python file.
PythonCard Codeeditor also uses tabnanny, as far as i can remember.
[...]


regards
--
Franz Steinhaeusler
Jul 18 '05 #7

P: n/a
Franz Steinhaeusler wrote:
On Tue, 21 Dec 2004 08:36:31 -0500, Steve Holden <st***@holdenweb.com>
wrote:

Franz Steinhaeusler wrote:

[...]
Oh sorry, I meant
def a():
->print
..->print

C:\Python23\Lib>tabnanny.py -v c:\franz.py
'c:\\franz.py': *** Line 3: trouble in tab city! ***
offending line: ' \tprint\n'
indent not equal e.g. at tab size 1

C:\Python23\Lib>python -c "print repr(open('c:/franz.py').read())"
'def a():\n\tprint\n \tprint\n'

C:\Python23\Lib>c:/franz.py

C:\Python23\Lib>


Well, you've probably answered your own question, then. Do you think
tabnanny is a useful piece of code now?

Not really soo useful, because most syntax and also indentation errors
are actually detected by invoking python, i.e. the command compile.
But as combination for this: yes why not.
I looked for Stanis spe editor, which uses a combination of these two.

The background is:

I'm a member of the wxPython project Drpython (Python text editor
and much more), and wanted also check the usefulness of a kind of syntax
check, which should run, before saving a Python file.
PythonCard Codeeditor also uses tabnanny, as far as i can remember.

[...]

regards


I've used drpython, and liked it. I think it would be a good way for
people to start to use the language, as it avoids the "just the command
line" syndrome without being as complex as IDLE or PythonWin. In short,
just about right for a beginner.

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Jul 18 '05 #8

P: n/a
On Tue, 21 Dec 2004 09:34:47 -0500, Steve Holden <st***@holdenweb.com>
wrote:
Hello Steve,
I've used drpython, and liked it.
thank you, I'm sure, our project Admin will be pleased to hear this :)
I think it would be a good way for
people to start to use the language,
yes, this project is intended to fulfill this purpose.
as it avoids the "just the command
line" syndrome without being as complex as IDLE or PythonWin.
I think, it isn't too far away from these two anymore ;)
Considering the expansion with scripts and plugins,
and there are a several of them available.
In short,
just about right for a beginner.
I use it exclusively for a few months for any Python source editing.

regards
Steve


regards,
--
Franz Steinhaeusler
Jul 18 '05 #9

P: n/a

"Steve Holden" <st***@holdenweb.com> wrote in message
news:qIVxd.57751$Jk5.26179@lakeread01...
Do you think tabnanny is a useful piece of code now? I used it a lot when
I first started using Python, and still run it over code from unknown
sources (no pun intended) from time to time.
I think it's a lot less useful today than it was a few
years ago, but it's still useful if you're stuck with an
editor that doesn't give you a robust set of options,
or if you've got to check a lot of modules in a library.

I think most python-aware editors have included
the needed functionality, or at least some reasonable
approximation.

I know what I would like to see in an editor:

First, it autodetects whether the module uses
tabs consistently, spaces consistently or a
mixture. If it uses tabs consistently, it then
uses the current default.

If it uses spaces consistently, it should also
autodetect the indentation setting in use in
the module and offer to change it if it's
different from the current default indentation
setting.

If it's inconsistent, it should make an attempt
to deduce the model the creating software
used; if it can it should change it to the
default setting without complaining. Otherwise
it should complain.

John Roth
regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119


Jul 18 '05 #10

P: n/a
John Roth wrote:
[...]
I know what I would like to see in an editor:

First, it autodetects whether the module uses
tabs consistently, spaces consistently or a
mixture. If it uses tabs consistently, it then
uses the current default.

If it uses spaces consistently, it should also
autodetect the indentation setting in use in
the module and offer to change it if it's
different from the current default indentation
setting.

If it's inconsistent, it should make an attempt
to deduce the model the creating software
used; if it can it should change it to the
default setting without complaining. Otherwise
it should complain.

John Roth

Sounds like WingIDE to me. I'm a recent convert, but one feature that
impressed me was the instant warning I got when I indented code with
spaces in a tab-oriented source file.

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Jul 18 '05 #11

P: n/a
On Tue, 21 Dec 2004 09:06:12 -0600, "John Roth"
<ne********@jhrothjr.com> wrote:

"Steve Holden" <st***@holdenweb.com> wrote in message
news:qIVxd.57751$Jk5.26179@lakeread01...
Do you think tabnanny is a useful piece of code now? I used it a lot when
I first started using Python, and still run it over code from unknown
sources (no pun intended) from time to time.
I think it's a lot less useful today than it was a few
years ago, but it's still useful if you're stuck with an
editor that doesn't give you a robust set of options,
or if you've got to check a lot of modules in a library.

I think most python-aware editors have included
the needed functionality, or at least some reasonable
approximation.

I know what I would like to see in an editor:

First, it autodetects whether the module uses
tabs consistently, spaces consistently or a
mixture. If it uses tabs consistently, it then
uses the current default.

If it uses spaces consistently, it should also
autodetect the indentation setting in use in
the module and offer to change it if it's
different from the current default indentation
setting.

If it's inconsistent, it should make an attempt
to deduce the model the creating software
used; if it can it should change it to the
default setting without complaining. Otherwise
it should complain.

Again, DrPython does this almost as you described ;)

There is an option in the preferences:
"Use File's Indentation"

and the indent setttings are set to the one,
what is found in the opened source file.

In the status line, the mode "SPACES" or "TABS" or
"MIXED" is displayed.

There are also the functions:
Edit=>Whitespace=>Check Indentation
Edit=>Whitespace=>Set Indentation to spaces
(replaces all tabs with the preset nr of spaces for tab

Exception 1:
(it could set then the tab mode to spaces)
and respectively:
Edit=>Whitespace=>Set Indentation to spaces

Exception 2:

If open a file, there could be a check, whether
tabs and spaces indentations are mixed, try to correct
if possible or complain (let the user decide).

=> Feature Request ;)

regards,
--
Franz Steinhaeusler
Jul 18 '05 #12

P: n/a
I'm told Tabnanny was inspired by lint, the Unix utiltity to check C sources
(and probably others). Lint was primarily useful in days long ago when CPUs
were slow and a compile used a significant amount of resources. In a
multiuser environment (we ran an Intel 286 in multiuser mode!!), the
compiles could bring everyone else to a crawl. Lint was used because it was
a less-CPU intensive way to catch bonehead errors and fix them before using
precious compile time.

Today,lint and Tabnanny may still have their uses as noted by others to
cleanup the tab/space conundrum.
--
Mike

"Franz Steinhaeusler" <fr*****************@utanet.at> wrote in message
news:en********************************@4ax.com...
Hi, I looked at tabnanny to check
a python source file.

But I didn't find anything, tabnanny
is able to find, what couldn't be found
by compile command.

Or have I missed something?

best regards,
--
Franz Steinhaeusler

Jul 18 '05 #13

P: n/a
"Yet Another Mike" wrote:
I'm told Tabnanny was inspired by lint, the Unix utiltity to check C sources (and probably
others).


well, I'd say tabnanny was tim's attempt to show guido that it really
was possible to create a perfect version of guido's original tabpolice
script:

http://groups-beta.google.com/group/...ad32f305538b36

</F>

Jul 18 '05 #14

P: n/a
"Yet Another Mike" <sa**************@yahoo.com> writes:
I'm told Tabnanny was inspired by lint, the Unix utiltity to check C sources
(and probably others). Lint was primarily useful in days long ago when CPUs
were slow and a compile used a significant amount of resources. In a
multiuser environment (we ran an Intel 286 in multiuser mode!!), the
compiles could bring everyone else to a crawl. Lint was used because it was
a less-CPU intensive way to catch bonehead errors and fix them before using
precious compile time.


Originally, lint caught errors the C compiler didn't flag as
errors. For example:

int *main = { ..... } ;

The C compiler would build and link that just fine on v7. lint would
complain about it. Of course, if you used the right ints to fill the
array, it would produce a valid executable.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #15

P: n/a
Steve Holden schreef:
Sounds like WingIDE to me. I'm a recent convert, but one feature that
impressed me was the instant warning I got when I indented code with
spaces in a tab-oriented source file.


From the SciTE/Scintilla docs:

| tab.timmy.whinge.level
|
| For Python code, checks whether indenting is consistent. The default, 0
| turns off indentation checking, 1 checks whether each line is
| potentially inconsistent with the previous line, 2 checks whether any
| space characters occur before a tab character in the indentation, 3
| checks whether any spaces are in the indentation, and 4 checks for any
| tab characters in the indentation.
| 1 is a good level to use.

It's also in de wxSTC docs:
<http://www.yellowbrain.com/stc/lexing.html#setlexer>
(Below the lexers table.)
--
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
Jul 18 '05 #16

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Franz Steinhaeusler wrote:

| Not really soo useful, because most syntax and also indentation errors
| are actually detected by invoking python, i.e. the command compile.
| But as combination for this: yes why not.
| I looked for Stanis spe editor, which uses a combination of these two.

Just because Python compiles and runs something does not mean that there
are no indentation errors. tabnanny works great because it removes all
ambiguous cases so you never have to worry about it. We use it as part
of our test suite to guard against misconfigured editors.

(again using '.' instead of space) Why would you want to allow '.\tprint
foo' in Python source when you could clean it up to be the totally
unambigous '........print foo'. As a more rational example, would you
want to allow '....\tprint foo', which will totally confuse someone with
their editor misconfigured with 4 char tabs?
- --
Stuart Bishop <st****@stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFByp4nAfqZj7rGN0oRAoq9AJ4scAe0A3aFnx7jRZuqtR XXaxAcRgCfYkVf
FbH2HBFA4/44KgZfpiPuvNU=
=nyQt
-----END PGP SIGNATURE-----
Jul 18 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.