[Pythonmac-SIG] algorithm wanted

Ramm, Henning Henning.Ramm at mediapro-gmbh.de
Tue Feb 1 15:44:48 CET 2005


Hi there!

I'm looking for a better algorithm...

In a print project I must know if some page needs every CMYK separation or just some;
I keep this info in a boolean list like [True, True, False, True] for C,M,K (no Y plate).
But our workflow database needs a string like "CM0K" (plate letter or zero).
How can I convert this best?
Here is my code:

class ProcessColors:    
    _cmykMap = ['C', 'M', 'Y', 'K']
    
    def __init__(self, C=False, M=False, Y=False, K=True):
        self.werte = [C,M,Y,K]
        
    def bool2str(self, werte=None):
        """converts a list of booleans to a CMYK color string,
        e.g. [True, False, False, True] to 'C00K'"""
        if not werte: werte = self.werte
        for i in range(0,4):
            if werte[i]:
                werte[i] = self._cmykMap[i]
            else:
                werte[i] = '0'
        return string.join(werte, '')
    
    def str2bool(self, werte='000K'):
        """converts a CMYK color string to a list of booleans,
        e.g. 'CM0K' to [True, True, False, True]"""
        werte = list(werte)
        for i in range(0,4):
            if werte[i]==self._cmykMap[i]:
                werte[i] = True
            else:
                werte[i] = False
        return werte


I hope the same is possible without 'if' and 'for', perhaps some lambda+boolean wizardry?

Best regards,
-----------------------
Henning Hraban Ramm
Südkurier Medienhaus / MediaPro
Abt. Systembetreuung


More information about the Pythonmac-SIG mailing list