Problem of Readability of Python

Steven Bethard steven.bethard at gmail.com
Wed Oct 10 20:04:22 CEST 2007


Kevin wrote:
> Am I missing something, or am I the only one who explicitly declares
> structs in python?
> 
> For example:
> FileObject = {
>     "filename" : None,
>     "path" : None,
>     }
> 
> fobj = FileObject.copy()
> fobj["filename"] = "passwd"
> fobj["path"] = "/etc/"

Yes, I think this is the only time I've ever seen that. I think the 
normal way of doing this in Python is:

     class FileObject(object):
         def __init__(self, filename, path):
             self.filename = filename
             self.path = path

     fobj = FileObject(filename='passwd', path='etc')

STeVe



More information about the Python-list mailing list