[Tutor] Python program design

Tiger12506 keridee at jayco.net
Tue Jul 24 03:54:41 CEST 2007


> Then I would need to get the file size (but this is giving me an error at
> the moment)
>    for name in files:
>        s = sum(getsize(join(root, name)
>        print s  (syntax error here. I have not figured it out yet. There
> are spaces in the path/filename combo)
>   (code to parse the file extension here)

The line should be
s = getsize(join(root, name))

which will print the file size for each "name in files"

>
> Back to the data though, should I create something like these while 
> reading
> the media and prior to inserting it into the database?
> [disk label, disk id [root[dir[file,size,type, permissions]]]] in a
> dictionary or tuple? or use a list?
>
> or flat in a dictionary, tuple or list like
> [disk label, disk id, root,dir,filename,size,type,permissions]
>
> When it has completed the scan I want to insert it into the database with
> the following fields
> disk label, disk id, root directory, path, filename, file size, file type,
> original file permissions, and comment field.  (Does anyone thing I should
> have any other fields? Suggestions welcome)
>
> Thank you in advance.  If this is off topic, please reply off the list and
> let me know.

Don't take my word for it completely, but a few things to consider.
Disc IDs are the most likely to be unique, so I would use those as the keys
However, It is possible for two discs to have the same IDs, so for 
stability, I would
suggest using a tuple as a key. I know it's possible even to have two 
different discs
with the same ID and label, but it's not likely.

{(discID, discLbl) : [information in list],
 ...
}

You may wish to build a dict inside your dict.

{(discID, discLbl): {'dir': '...',
                                 'filename': '...",
etc.

I don't know how you want to use it, but keeping the root directory is not 
very useful. If you ever want to transfer your files to another computer 
where the drive letters are different, or classic example ~ you build your 
dict from a usb device that you plug in  in a different order later so that 
it's assigned a different drive letter. I would suggest using the drive ID 
and some sort of api to find the drive letter at runtime.

HTH,
JS 



More information about the Tutor mailing list