[Python-ideas] Class autoload

Nathaniel Smith njs at pobox.com
Sat Mar 3 19:23:31 EST 2018


On Sat, Mar 3, 2018 at 9:12 AM, Jamesie Pic <jpic at yourlabs.org> wrote:
>
> Hello everybody,
>
> I thought perhaps we could allow the usage of a "new" keyword to instanciate
> an object, ie:
>
>    obj = new yourmodule.YourClass()
>
> In this case, it would behave the same as from yourmodule import YourClass;
> obj = YourClass(), except that it wouldn't need to be imported. This would
> also eliminate the need to manage an import list at the beginning of a
> script in most case.

The 'py' library has something like this for stdlib libraries. You
could imagine extending it to handle arbitrary auto-imports, e.g.

  import auto_import as ai

  obj = ai.yourmodule.YourClass()

The 'py' version never really caught on, but if you really like the
idea there's nothing stopping you from implementing and using
something similar today.

-n

-- 
Nathaniel J. Smith -- https://vorpus.org


More information about the Python-ideas mailing list