Pointer to Image

Chris Jankowski cjankowski at hbr-inc.com
Fri Oct 22 19:33:43 CEST 2004


Jeff Shannon <jeff at ccvcorp.com> wrote in message news:<10ng2p7eddu4b3a at corp.supernews.com>...
> 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

Hey Jeff,
Thanks for the pointers.  I am still new to Python and sometimes do
things the hard way, because I don't know any better.  (yet)  I just
copied this from the cytpes documentation and plugged in my variable
names.

The part that is confusing to me, still has not been answered.  

This DLL file has several functions. One is a handler that needs to be
set to a Python function.  How do I pass it an address to make this
happen?

def myOutputHandler(infotype, param):
    print("outhandler")
    if infotype == "OT_TEXT":
        print param
##[...]

myOcr.OCRSetOutputHandler(address of myOutputHandler?) ###
??????????????

Thanks,

Chris J.



More information about the Python-list mailing list