Skip to main content
added 63 characters in body
Source Link
joel
  • 8.1k
  • 5
  • 43
  • 75

Perhaps not the best, but you could do

def getCodec(name, **kwargs):
    codecObjects = {
        'aac' : AACCodec,
        'ogg' : OGGCodec,
        'flac': FLACCodec
    }

    return codeObjects[name](**kwargs)

After all, you are trying to map a string to a class, but only need to instantiate one

Perhaps not the best, but you could do

codecObjects = {
    'aac' : AACCodec,
    'ogg' : OGGCodec,
    'flac': FLACCodec
}

return codeObjects[name](**kwargs)

After all, you are trying to map a string to a class, but only need to instantiate one

Perhaps not the best, but you could do

def getCodec(name, **kwargs):
    codecObjects = {
        'aac' : AACCodec,
        'ogg' : OGGCodec,
        'flac': FLACCodec
    }

    return codeObjects[name](**kwargs)

After all, you are trying to map a string to a class, but only need to instantiate one

Source Link
joel
  • 8.1k
  • 5
  • 43
  • 75

Perhaps not the best, but you could do

codecObjects = {
    'aac' : AACCodec,
    'ogg' : OGGCodec,
    'flac': FLACCodec
}

return codeObjects[name](**kwargs)

After all, you are trying to map a string to a class, but only need to instantiate one