mod_speling for python

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

    mod_speling for python

    Hi,
    I'm not looking to get into a debate about case-sensitive vs.
    insensitive programming languages,
    but I was looking for suggestions about how it might be possible to
    add a hook to the python parser similar to the Apache mod_speling
    module (links below). So that for example if there is a NameError
    exception, python walks the globals() and locals() to see if it might
    be just a minor spelling/capitalization error.

    I can see how this might be done for ImportErrors, using ihooks or iu,
    but I don't see how to do it for NameErrors. The python compiler
    module doesn't seem to be the answer.

    I know there are drawbacks, disadvantages, this is "evil", etc. I
    only wanted to know what ways there are to add such a hook if it is
    possible without altering the C source for python itself.

    Possible End-User Solution A:
    Simply add an "import spelling" to a python file to enable
    spell-checking, sort of like how you use the psyco module (speaking of
    which, how many times have you misspelled that).

    Possible End-User Solution B:
    Create an alternative executable that wraps the python interpreter.
    This wrapper may or may not have to use its own source code parser,
    like the unreleased mobius-python project.





    Free, secure and fast downloads from the largest Open Source applications and software directory - SourceForge.net

  • Skip Montanaro

    #2
    Re: mod_speling for python


    prtk3> ... if there is a NameError exception, python walks the globals()
    prtk3> and locals() to see if it might be just a minor
    prtk3> spelling/capitalization error.

    prtk3> I can see how this might be done for ImportErrors, using ihooks
    prtk3> or iu, but I don't see how to do it for NameErrors. The python
    prtk3> compiler module doesn't seem to be the answer.

    prtk3> I know there are drawbacks, disadvantages, this is "evil", etc.
    prtk3> I only wanted to know what ways there are to add such a hook if
    prtk3> it is possible without altering the C source for python itself.

    Take a look at sys.excepthook. Actual implementation is left as an exercise
    for the reader. <wink>

    Skip

    Comment

    • Harald Massa

      #3
      Re: mod_speling for python

      > prtk3> I know there are drawbacks, disadvantages, this is "evil",[color=blue]
      > etc. prtk3> I only wanted to know what ways there are to add such
      > a hook if prtk3> it is possible without altering the C source for
      > python itself.
      >
      > Take a look at sys.excepthook. Actual implementation is left as an
      > exercise for the reader. <wink>[/color]

      And be carefull: it breaks the Zen of Python and thereby removes it's mojo.

      Comment

      • Josiah Carlson

        #4
        Re: mod_speling for python

        > I know there are drawbacks, disadvantages, this is "evil", etc. I[color=blue]
        > only wanted to know what ways there are to add such a hook if it is
        > possible without altering the C source for python itself.[/color]

        Ambiguities during execution are bad. I've got two functions Foo and
        foO, if I type in foo, what did I mean?

        - Josiah

        Comment

        • Skip Montanaro

          #5
          Re: mod_speling for python

          [color=blue][color=green]
          >> I know there are drawbacks, disadvantages, this is "evil", etc. I
          >> only wanted to know what ways there are to add such a hook if it is
          >> possible without altering the C source for python itself.[/color][/color]

          Josiah> Ambiguities during execution are bad. I've got two functions
          Josiah> Foo and foO, if I type in foo, what did I mean?

          I didn't interpret the OP's question as wanting to automatically map Foo to
          foO, but to give the user a more helpful error message, suggesting other
          candidate names which he might have mistyped.

          Skip

          Comment

          Working...