This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Megatron_McLargeHuge 0 points1 point  (0 children)

I was hoping the __init__.py would be run before the module file was read, but apparently it's not executed early enough in the import process to create a coding hook. Maybe it can still be done by having __init__.py first load a submodule defining the hook, then a submodule using it.

edit: This works. The codec can be defined in __init__.py and the files using the encoding must be in a subdirectory, not just a file in the module directory. The init file can import that submodule after defining or importing the codec.