[sugar] Python coding conventions
Dan Williams
dcbw
Mon Oct 2 09:44:54 EDT 2006
On Mon, 2006-10-02 at 14:13 +0200, Marco Pesenti Gritti wrote:
> Ian Bicking wrote:
> > Marco Pesenti Gritti wrote:
> >> Eeeeh here comes my hate for python imports. What I'd really want in
> >> the code is:
> >>
> >> from sugar import presence
> >>
> >> ps = presence.PresenceService()
> >>
> >> Now, is there a way to get that without stuffing all the presence
> >> service in presence.py. Or more in general can you elaborate on a way
> >> to organize code in python that doesn't suck :) I guess we have been
> >> trying to emulate java like packaging with generally one class per
> >> file, but that doesn't seem to play well with python imports.
> >>
> >> Anyway it would be great to solve this in a good way. I hate what we
> >> have currently.
> >
> > You can put everything in presence/__init__.py. I don't like using
> > __init__.py this way, though; it's a little quirky as a file
> > (ImportError's in it are swallowed), and by itself it has a rather
> > ambiguous name. So I typically put something like this in there:
> >
> > # presence/__init__.py
> > from presenceservice import PresenceService
> >
> > Then you can do "from presence import PresenceService". When you then
> > try to track down PresenceService you'll have a little indirection,
> > but usually it's not too distracting.
> >
> > One downside is that there is then no way to import (and hence load)
> > some of the code without importing all of it. I.e., if you wanted
> > access to something in presence/ but not PresenceService, you would
> > end up implicitly importing PresenceService whether you wanted to or not.
> >
>
> I tried to use lower case names for modules and it works better. Unless
> Dan disagree I think we should go with this style for modules. Ian, it
> would be great if you could come up with a simple code style document.
That sounds fine.
Dan
> Marco
> _______________________________________________
> Sugar mailing list
> Sugar at laptop.org
> http://mailman.laptop.org/mailman/listinfo/sugar
More information about the Sugar-devel
mailing list