[Python-ideas] Making Path() a built in.
steve at pearwood.info
Sat Jun 9 08:40:25 EDT 2018
On Wed, Jun 06, 2018 at 07:05:35PM +0100, Barry Scott wrote:
> I assume the the idea is that everybody has Path available without the need to do the import dance first.
> If its for personal convenience you can always do this trick, that is used by gettext to make _ a builtin.
> import pathlib
> import builtings
> builtins.__dict__['Path'] = pathlib.Path
The public API for getting the namespace of an object is vars():
but since builtins is just a module, the best way to add a new
attribute to it is:
builtins.Path = pathlib.Path
More information about the Python-ideas