Movatterモバイル変換


[0]ホーム

URL:


Strange error with unbound method

Fernando Rodríguezspamers at must.die
Mon Apr 16 12:26:17 EDT 2001


Hi!I have a class called ParaStyle (see code below). This class has amethod called makeBlackAndWhite that returns a new instance of classParaStyle.I want to transform a list of ParaStyle instances into a list of theresult of applying the makeBlackAndWhite method of each instance.If I do:paraStyles = map( ParaStyle.makeBlackAndWhite, paraStyles )I get the following error:TypeError: unbound method must be called with class instance 1st argumentWhile if I do it with a for loop:l = []for para in paraStyles:    l.append( para.makeBlackAndWhite() )I dont get any error!  =:-OWhat's going on???? O:-)-----------ParaStyle Class-------------------class ParaStyle(BaseObject):    """Contiene toda la info sobre un estilo de párrafo: el estilo    de sus caracteres (una instancia de un CharStyle), su alineación,    el 'leading' o separación entre lineas, el indentado (una instancia    de algna de las siguientes clases: NullIndent (sin indentado),    NormalIndent, FrenchIndent o FirstLineIndent)y cual    es el siguiente."""    # Tipos de alineación    alignment = { 'left': '\ql',                  'right': '\qr',                  'centered': '\qc',                  'justified': '\qj',                  'none' : ''}    # Tipos de separación (leading)    leading = { 1:'',                1.5:"\sl360\slmult1",                2:"\sl480\slmult1" }        # TODO: debe de comprobar que los parámetros alignment,    # y leading son del tipo correcto. Sino, debe de    # levantar una excepción    # Si no es por omisión (no contiene la palabra default o    # normal) y no tiene basedOn, probablemente sea un    # error. Avisar.    def __init__( self,                  names,                  charStyle = NullCharStyle(),                  next = NullParaStyle(),                  basedOn = NullParaStyle(),                  indent = NullIndent(),                  alignment = 'none',                  leading = 1 ):        if not alignment in ParaStyle.alignment.keys():            raise UnknownAlignment, str( alignment ) + ' isn`t a validalignment'        if not leading in ParaStyle.leading.keys():            raise UnknownLeading, str( leading ) + ' isn`t a valid leading'                if not names[0] == 'default' and basedOn.__class__ == NullParaStyle:                raise NoParent, str( names ) + ' has no basedOn. ' + \                      'Since it`s not the default one, it must have a basedOn'        self.names = names        self.basedOn = basedOn        # si no se indica un next, ha de apuntar a sí mismo        if next.__class__ == NullParaStyle:            self.next = self        else:            self.next = next                # Hacemos la herencia de next, indent, alignment y leading        # en el momento de construir la instancia        if basedOn.__class__ == NullParaStyle:                                   self.alignment = alignment            self.indent = indent            self.leading = leading            self.charStyle = charStyle        else:            if charStyle.__class__ == NullCharStyle:                self.charStyle = basedOn.charStyle            else:                self.charStyle = charStyle                                    if alignment == 'none':                self.alignment = basedOn.alignment            else:                self.alignment = alignment            if indent.__class__ == NullIndent:                self.indent = basedOn.indent            else:                self.indent = indent            if leading == 1:                self.leading = basedOn.leading            else:                self.leading = leading                    def makeBlackAndWhite( self ):        """Versión en blanco y negro del formato        ¡¡Ojo!! Si el next es self, tenemos un poblema: para construir        un BW, necesitamos previamente ese BW para pasarlo al constructor.        Esto causaría un bucle sin fin. Para evitarlo, construimos        primero una versión parcial sin el next, y luego le añadimos una        ref a sí mismo.        """        if self.next == self:            partial = ParaStyle( names = self.names,                                 charStyle =self.charStyle.makeBlackAndWhite(),                                 basedOn = self.basedOn.makeBlackAndWhite(),                                 indent = self.indent.makeBlackAndWhite(),                                 leading = self.leading,                                 alignment = self.alignment )            partial.next = partial            return partial        else:            return ParaStyle( names = self.names,                              charStyle = self.charStyle.makeBlackAndWhite(),                              basedOn = self.basedOn.makeBlackAndWhite(),                              next = self.next.makeBlackAndWhite(),                              indent = self.indent.makeBlackAndWhite(),                              leading = self.leading,                              alignment = self.alignment )    //-----------------------------------------------//Fernando Rodriguez Romero////frr at mindless dot com//------------------------------------------------


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp