I would go with the latter.  If you instantiate the connection on the class
itself, it should only get initialized once per runtime.


On Wed, Apr 24, 2013 at 5:47 PM, Christopher Bare <[email protected]
> wrote:

> Hi Python folks,
>
> I'm cooking up some client code in Python for a REST web service. The
> service provides CRUD operations on various types of objects.
>
> So, which looks more natural in Python?
>
> rest_service.store(my_object)
>
> or
>
> my_object.store()
>
> ...and, if it's the latter, do I keep the connection information in a
> module scope constant? Is that considered bad, like a global variable? It
> seems cumbersome to pass a connection object into the constructor of every
> storable object. Java-esque factory objects doing dependency injection seem
> cumbersome, too.
>
> Is there another cleaner way? Any hints?
>
> Thanks,
>
> - Chris
>
>

Reply via email to