Generate a new object each time a name is imported

Jonathan Gardner jgardner at jonathangardner.net
Sun Aug 2 03:38:22 EDT 2009


On Aug 2, 12:35 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
>
> I'm looking for a way to hide the generation of objects from the caller,
> so I could do something like this:
>
> from Module import factory() as a  # a == "Object #1"
> from Module import factory() as b  # b == "Object #2"
>

Explicit is better than implicit. In other words, I don't see why you
need to hide this. Just import the factory function and call it.

from Module import factory
a = factory()



More information about the Python-list mailing list