[Python-ideas] Class autoload

Eric V. Smith eric at trueblade.com
Sat Mar 3 12:38:20 EST 2018


On 3/3/2018 12:12 PM, Jamesie Pic wrote:
> 
> Hello everybody,
> 
> I thought perhaps we could allow the usage of a "new" keyword to 
> instanciate an object, ie:
> 
>     obj = new yourmodule.YourClass()

I'd just do:
     import yourmodule
     obj = yourmodule.YourClass()

Or as one line, if that's your thing:
     import yourmodule; obj = yourmodule.YourClass()

Imports don't need to be at the top of the file. If you want to delay 
loading modules, that's fine. It's pretty cheap for an already loaded 
module.

In my opinion it's not worth a new keyword and something else to learn.

Eric

> 
> 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.
> 
> I'm really not proud of this idea but PHP has had autoload for years and 
> when i open scripts with hundred lines of imports it makes me think 
> Python could do something about this.
> 
> Thanks in advance for your feedback
> 
> Best regards
> 
> -- 
>> 
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
> 


More information about the Python-ideas mailing list