Tabnanny really useful?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Franz Steinhaeusler

    #1

    Tabnanny really useful?

    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
  • John Roth

    #2
    Re: Tabnanny really useful?


    "Franz Steinhaeusler" <franz.steinhae usler@utanet.at > wrote in message
    news:envds0pfjn benoll9nh9b4l5t ca4kn9d00@4ax.c om...[color=blue]
    > 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?[/color]

    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[color=blue]
    >
    > best regards,
    > --
    > Franz Steinhaeusler[/color]

    Comment

    • Franz Steinhaeusler

      #3
      Re: Tabnanny really useful?

      On Mon, 20 Dec 2004 13:00:39 -0600, "John Roth"
      <newsgroups@jhr othjr.com> wrote:
      [color=blue]
      >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.[/color]

      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

      Comment

      • Fredrik Lundh

        #4
        Re: Tabnanny really useful?

        Franz Steinhaeusler wrote:
        [color=blue]
        > 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.[/color]

        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('fran z.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>



        Comment

        • Franz Steinhaeusler

          #5
          Re: Tabnanny really useful?

          On Tue, 21 Dec 2004 10:24:40 +0100, "Fredrik Lundh"
          <fredrik@python ware.com> wrote:
          [color=blue]
          >Franz Steinhaeusler wrote:
          >[color=green]
          >> 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.[/color]
          >
          >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('fran z.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>
          >
          >[/color]

          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

          Comment

          • Steve Holden

            #6
            Re: Tabnanny really useful?

            Franz Steinhaeusler wrote:
            [color=blue]
            > On Tue, 21 Dec 2004 10:24:40 +0100, "Fredrik Lundh"
            > <fredrik@python ware.com> wrote:
            >
            >[color=green]
            >>Franz Steinhaeusler wrote:
            >>
            >>[color=darkred]
            >>>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.[/color]
            >>
            >>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('fran z.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>
            >>
            >>[/color]
            >
            >
            > 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 >[/color]

            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

            Comment

            • Franz Steinhaeusler

              #7
              Re: Tabnanny really useful?

              On Tue, 21 Dec 2004 08:36:31 -0500, Steve Holden <steve@holdenwe b.com>
              wrote:
              [color=blue]
              >Franz Steinhaeusler wrote:
              >
              >[...][color=green]
              >>
              >> 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 >[/color]
              >
              >Well, you've probably answered your own question, then. Do you think
              >tabnanny is a useful piece of code now?[/color]

              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.
              [color=blue]
              >[...][/color]

              regards
              --
              Franz Steinhaeusler

              Comment

              • Steve Holden

                #8
                Re: Tabnanny really useful?

                Franz Steinhaeusler wrote:
                [color=blue]
                > On Tue, 21 Dec 2004 08:36:31 -0500, Steve Holden <steve@holdenwe b.com>
                > wrote:
                >
                >[color=green]
                >>Franz Steinhaeusler wrote:
                >>
                >>[...]
                >>[color=darkred]
                >>>Oh sorry, I meant
                >>>def a():
                >>>->print
                >>>..->print
                >>>
                >>>C:\Python23\ Lib>tabnanny.py -v c:\franz.py
                >>>'c:\\franz.p y': *** 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>[/color]
                >>
                >>Well, you've probably answered your own question, then. Do you think
                >>tabnanny is a useful piece of code now?[/color]
                >
                >
                > 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.
                >
                >[color=green]
                >>[...][/color]
                >
                >
                > regards[/color]

                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

                Comment

                • Franz Steinhaeusler

                  #9
                  Re: Tabnanny really useful?

                  On Tue, 21 Dec 2004 09:34:47 -0500, Steve Holden <steve@holdenwe b.com>
                  wrote:


                  Hello Steve,
                  [color=blue]
                  >I've used drpython, and liked it.[/color]

                  thank you, I'm sure, our project Admin will be pleased to hear this :)
                  [color=blue]
                  >I think it would be a good way for
                  >people to start to use the language,[/color]

                  yes, this project is intended to fulfill this purpose.
                  [color=blue]
                  >as it avoids the "just the command
                  >line" syndrome without being as complex as IDLE or PythonWin.[/color]

                  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.
                  [color=blue]
                  >In short,
                  >just about right for a beginner.[/color]

                  I use it exclusively for a few months for any Python source editing.
                  [color=blue]
                  >
                  >regards
                  > Steve[/color]

                  regards,
                  --
                  Franz Steinhaeusler

                  Comment

                  • John Roth

                    #10
                    Re: Tabnanny really useful?


                    "Steve Holden" <steve@holdenwe b.com> wrote in message
                    news:qIVxd.5775 1$Jk5.26179@lak eread01...
                    [color=blue]
                    > 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.[/color]

                    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[color=blue]
                    >
                    > 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[/color]

                    Comment

                    • Steve Holden

                      #11
                      Re: Tabnanny really useful?

                      John Roth wrote:
                      [...][color=blue]
                      > 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
                      >[/color]
                      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

                      Comment

                      • Franz Steinhaeusler

                        #12
                        Re: Tabnanny really useful?

                        On Tue, 21 Dec 2004 09:06:12 -0600, "John Roth"
                        <newsgroups@jhr othjr.com> wrote:
                        [color=blue]
                        >
                        >"Steve Holden" <steve@holdenwe b.com> wrote in message
                        >news:qIVxd.577 51$Jk5.26179@la keread01...
                        >[color=green]
                        >> 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.[/color]
                        >
                        >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
                        >approximatio n.
                        >
                        >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.
                        >[/color]
                        [color=blue]
                        >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.[/color]


                        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=>Whitespac e=>Check Indentation
                        Edit=>Whitespac e=>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=>Whitespac e=>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

                        Comment

                        • Yet Another Mike

                          #13
                          Re: Tabnanny really useful?

                          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" <franz.steinhae usler@utanet.at > wrote in message
                          news:envds0pfjn benoll9nh9b4l5t ca4kn9d00@4ax.c om...[color=blue]
                          > 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[/color]


                          Comment

                          • Fredrik Lundh

                            #14
                            Re: Tabnanny really useful?

                            "Yet Another Mike" wrote:
                            [color=blue]
                            > I'm told Tabnanny was inspired by lint, the Unix utiltity to check C sources (and probably
                            > others).[/color]

                            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:



                            </F>



                            Comment

                            • Mike Meyer

                              #15
                              Re: Tabnanny really useful?

                              "Yet Another Mike" <saynotodevilsp am@yahoo.com> writes:
                              [color=blue]
                              > 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.[/color]

                              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 <mwm@mired.or g> http://www.mired.org/home/mwm/
                              Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

                              Comment

                              Working...