python version of C unsigned char
Question: I need help with a python version for this C code:

    
    
    #define HostBusy_high   0x02
    #define control_register    0x37a
    
    Out32 (control_register,(unsigned char)(Inp32(control_register) | HostBusy_high));
    

the Out32 and Inp32 are functions located in the inpout32.dll used to
interface parallel ports. These functions take hex values as their parameters.
I tried to code in python to get the desired value but that is not what I am
getting. See python version below:

    
    
    from ctypes import windll
    
    #parallel port instance
    p_port = windll.inpout32
    HostBusy_high = 0x02
    control_register = 0x37a
    
    write_data = write(p_port(Inp32(control_register) | HostBusy_high))
     Out32 (control_register,write_data))
    

With the code above i do not seem to get the value I want. I suspect it is the
unsigned value.

Thanks


Answer: Depends on why you need an unsigned char. For most purposes you'll just use a
Python integer. If you need to actually have a one-byte datum, you can use
Python's struct.pack to make a one-byte byte string out of an integer.

You can't, in general, get good results by doing line by line literal
translation of code between languages, without a good understanding of both
the source and target languages, as well as the body of code you're
translating.

