Python config file execfile


















Also, calling imp. I don't see a problem with remote code execution - there's nothing "remote" in loading a local config :- Also, you can pretty prevent all code execution that goes beyond simple evals by restricting the globals, e. If you wanna look at 3rd party solutions, prepare for overload. The number of alternative INI parsers alone is staggering. Follow Post Reply. Mike Meyer. You know, I've been there before.

It's kinda neat, but not something you really want to put in the hands of most users. You can make the syntax cleaner by using classes to hold the values instead of nested dicts, etc. I tried the simplest thing that could possibly work: With classes you factor out the commonality by factoring it into a base class that the others inherit from. Manipulate sys. Mitko Haralanov. Well, I am almost the only user of the config file, not the application and the few others are developers too so that's not an issue in this case.

Also it's not thread-safe; guarding it explicitly with a lock would make it even less clean. Ideally, I'd like to pass a new path to execfile without modifying the original even for the few milliseconds that execfile wlll probably take. With modules being singletons though, I don't think this is possible, or is it?

Thanks, that's basically what I did eventually and it works for my simple requirements. Another alternative would be to require the config files to be modules already in the path. File: ScriptWdg. Example 4. File: run. Example 5. Example 6. File: pytest.

Example 7. File: testexamples. Example 8. File: main. Example 9. File: config. Example The return value is None. The default locals act as described for function locals below: modifications to the default locals dictionary should not be attempted. Pass an explicit locals dictionary if you need to see effects of the code on locals after function execfile returns.



0コメント

  • 1000 / 1000