Pointer to Image

Jeff Shannon jeff at ccvcorp.com
Thu Oct 21 21:19:19 CEST 2004


Chris Jankowski wrote:

>    # [...]
>    setLanguage = myOcr.SetLanguage
>    setLanguage('ENGLISH',".")
>
>    setOutputMode = myOcr.SetOutputMode
>    setOutputMode("OM_TEXT")
>
>    setOutputHandler = myOcr.OCRSetOutputHandler
>    z = id(myOutputHandler)
>    errorx = setOutputHandler(z)
>    # [...]
>

As a minor stylistic note, I find your constant use of temporary local 
names of module functions to be distracting and even slightly 
confusing.  When you actually *call* a function, it's not immediately 
apparent whether that's a helper function that you've written yourself 
or whether it's a function in your OCR module -- I have to backtrack to 
see where the function came from, and I'm never quite sure whether I 
will find it somewhere in the current code block (because you've bound 
the imported function to a local name) or whether I should look 
elsewhere in the current module (because it's a function you've defined 
yourself).

I'd find the above code snippet *much* easier to read without the 
temporaries:

    myOcr.SetLanguage('ENGLISH', ".")
    myOcr.SetOutputMode("OM_TEXT")
    errorx = myOcr.OCRSetOutputHandler( id(myOutputHandler) )

To my eyes, this makes it much more clear where everything is found, and 
because it's so much shorter it's much easier to take in at a glance.

(I also share Thomas Heller's suspicion that passing the id() of 
myOutputHandler() is *not* what you want to do here.  The ID is merely 
an integer that Python uses internally to track an object; it is 
typically not useful for code that wants to *use* an object to know what 
its ID is.  You don't need to know your co-workers' social security 
numbers in order to work with them effectively, right?  Similarly, a 
Python object's ID is only needed in very special circumstances where 
the exact identity of an object is in question, and it's *not* needed 
for normal usage of an object such as being able to call a function object.)

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list