I have a Python module and I’d like to get that modules directory from inside itself. I want to do this because I have some files that I’d like to reference relative to the module.
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.
First you need to get a reference to the module inside itself.
Then you can use
__file__to get to the module file.Its directory is a
dirnameof that.