Preventing modules to be read from current working directory

S

ssjassal

Is there a way to instruct Python to import modules from standard
library even if there is one with the same name in the current working
directory? I was trying to import BaseHTTPServer.py from standard
library but was prevented by a python file with the same name in
current working directory (but there was no __init__.py). Can I use
some warning switch to print a warning on stdout?

Thanks,
Sunpreet.
 
R

Roy Smith

Is there a way to instruct Python to import modules from standard
library even if there is one with the same name in the current working
directory? I was trying to import BaseHTTPServer.py from standard
library but was prevented by a python file with the same name in
current working directory (but there was no __init__.py). Can I use
some warning switch to print a warning on stdout?

Thanks,
Sunpreet.

Sure, just modify sys.path so the current directory is not included. See
the documentation for the sys module in the library reference for more
details.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top