我试图弄清楚如何简化这段代码。每个 if 条件的逻辑基本相同,所以我想摆脱重复的 if:
if "video_codec" in profile:
self.video_codec = profile["video_codec"]
if "resolution_width" in profile:
self.resolution_width = profile["resolution_width"]
if "resolution_height" in profile:
self.resolution_height = profile["resolution_height"]
if "ratio" in profile:
self.ratio = profile["ratio"]
if "video_bitrate" in profile:
self.video_bitrate = profile["video_bitrate"]
if "profile" in profile:
self.profile = profile["profile"]
if "audio_codec" in profile:
self.audio_codec = profile["audio_codec"]
if "audio_channels" in profile:
self.audio_channels = profile["audio_channels"]
if "audio_bitrate" in profile:
self.audio_bitrate = profile["audio_bitrate"]
我希望这可以用 3-4 行而不是我的 18 行来完成。