In my Python script, I want to prevent certain stdlib modules, such as os and sys, from being imported. How would I accomplish this?
In my Python script, I want to prevent certain stdlib modules, such as os
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Taking you very literally, and if you just mean “to stub them out so that they won’t be loaded by a straight import”, not “make them unloadable by untrusted code”, then:
Of course, there is no module
systemso you might have meantsys, in which case you’re in trouble.If you’re trying to keep untrusted code from being able to do Bad Things, then take a look at http://wiki.python.org/moin/SandboxedPython and realise that you’re after something not immediately feasible.