Help me improve my Python Skills, please

Michael Hudson mwh21 at cam.ac.uk
Sat Jan 15 10:28:08 EST 2000


rjroy at takingcontrol.com (Robert Roy) writes:

> On 15 Jan 2000 00:43:41 -0700, tarude at whitestar.localdomain (Trebor A.
> Rude) wrote:
> 
> >
> >I just started picking up Python a few days ago, and am rather
> >enjoying it.  To help me learn it, I converted one of my old TCL
> >scripts into Python, which I've attached below. However, this being my 
> >first serious python script, I'm pretty sure I'm doing some things
> >less efficiently than necessary, through lack of familiarity with the
> >library and language in general. So I'd like to enlist the group's
> >help in improving the code. Logic, style, better ways of doing things, 
> >whatever.  Thanks in advance.
> >
> >A little explanation before the code.  The script recursively descends 
> >a directory structure, building a .jdb (Jukebox database) file for
> >each directory based on the mp3 tag info of the mp3s in that
> >directory and all its subdirectories. It also repairs damaged comment
> >fields caused by a slightly buggy encoder program.
> >
> The os.path.walk method provides an elegant way of recursing a
> directory structure. It might be useful here.

Actually, it's not that helpful in this case; this is because of the
line in the requirements "building a .jdb (Jukebox database) file for
each directory based on the mp3 tag info of the mp3s in that directory
and ALL ITS SUBDIRECTORIES" (my emphasis). os.path.walk does a
pre-order traversal of the tree, which means there'd be faffing around
to do to get the files from the subdirectories indexed into the
database for the root. Sure, it could be done, but rolling your own
post-order traversal has to be easier.

Cheers,
Michael



More information about the Python-list mailing list