On Wed, 01 Feb 2006 23:40:37 +0100, Daniel Nogradi wrote: > I'm relatively new to object oriented programming, so get confused > about its usage once in a while. Suppose there is a class Image that > has a number of methods, rotate, open, verify, read, close, etc. Then > to use this class my natural guess would be to have something like > > image = Image( ) > image.read( "myfile.jpg" ) > image.rotate( ) > image.close( ) > > But now it turns out that the PIL module uses this as > > image = Image.open( "myfile.jpg" ) > image.verify( ) > image.rotate( ) > image.close( ) > > Perhaps the real Image class of PIL doesn't have these methods > exactly, but doesn't matter, my point is the way it works. Is it > normal that instead of first creating an instance of a class, it > starts right away with one its methods? I of course understand that > the PIL people simply made a choice that their module works this way, > period, but I'm just wondering if it wouldn't have been more "logical" > to do it along the way of my first example. > > I guess it's just a matter of convention or how the programmer feels > like, but there are no conventions of this type? Which would be more > pythonic? Or I shouldn't worry and it's totally up to the developer?
You should take a look at the PIL source files, open() could surely be a class which takes a filename as an argument at construction time. If you run across such code, there is really no need to worry, some things are conventional and some are a matter of preference. In most cases diving into the source can help clarify a lot of your speculations, better hope the code is transparent, i hate reading non-readable code. :) -- A wise man knows he knows nothing. -- http://mail.python.org/mailman/listinfo/python-list