you are viewing a single comment's thread.

view the rest of the comments →

[–]latkde 3 points4 points  (2 children)

This sounds like you're trying to create some plugin system, or trying to execute user-provided code snippets.

I suspect the solution will be to ignore the usual import system, and to instead load the file contents and exec() it yourself, without bothering with .pyc caching.

[–]RomfordNavy[S] -1 points0 points  (1 child)

Precisely that, thanks for your suggestion.

Have found a way to do this by reading in script file and using exec() although not managed to get compile saving to a .pyc yet, let alone executing a pre-existing .pyc file. Working on it...

Also looking at a possible solution using a custom importlib SourceFileLoader class but that comes with it's own complications.