Deeply nested dictionaries - should I look into a database or am I just doing it wrong?

Andrew Berg bahamutzero8825 at gmail.com
Sat Jul 30 17:57:04 EDT 2011


As part of my muxer/encoder backend module, I need to store data in its
main class. While each instance won't typically store a lot of data, but
I really want it broken up into distinct categories so that a program
using the module won't need to figure out what piece of data refers to
what (e.g. is the current item using yadif via FFmpeg or AviSynth?) and
so that methods can be configured not to accept data that isn't relevant
(e.g. I don't want a bug in the calling program to cause the module to
use AviSynth methods if the user wants to use FFmpeg; I'd rather raise
an exception in this case). This is my (incomplete) layout of how I'd
nest the dictionaries:

> main
> 	demuxer
> 	video_encoder
> 	audio_encoder
> 	muxer
> io
> 	input_file
> 	prefix
> 	output_file
> video
> 	enabled
> 	mode (pal/ntsc/ivtc/film)
> 	fps
> 		fpsr
> 		fpsd
> 		fpsin
> 		fpsout
> audio
> 	enabled
> 	type (copy/aac/mp3/(l)pcm/etc.)
> avs
> 	enabled
> 	location
> 		dll
> 		plugins
> 	demuxer
> 		type (DirectShowSource/AVISource/etc.)
> 		dss_opts
> 		avis_opts
> 		
> 	filter
> 		deint/ivtc/none
> 			yadif
> 				enabled
> 				opts
> 			titvc
> 				enabled
> 				tdopts
> 				tfmopts
> 		fft3d
> 			enabled/gpu
> 			ffte
> 			ffts
> tsmuxer
> 	enabled
> 	location
> 	meta (T/F)
> x264
> 	enabled
> 	location
> 	usepreset (use presets or specify commands explicitly?)
> 	rcmethod
> 	crf
> 	bitrate
> 	cur_pass
> 	total_pass
> 	turbo (check x264 docs!)
> 	keyint
> 	min_keyint
> 	
> 	
> sox
> 	enabled
> 	location
> 	vol
> ffmpeg
> 	enabled
> 	location
> 	audio/video/both
> 	video
> 		x264
> 			
> 	audio
> 		acodec
> 	

Top-level items in the namespace of the object (e.g. QueueItem.x264).
Deeper are dictionaries within (e.g.
QueueItem.x264['avs']['filter']['fft3d']['ffte']).
Some of these can nest pretty deeply, so I wonder if dictionaries are
the right way to go.

-- 
CPython 3.2.1 | Windows NT 6.1.7601.17592 | Thunderbird 5.0
PGP/GPG Public Key ID: 0xF88E034060A78FCB



More information about the Python-list mailing list