Opticraft Community

Discussion forum => Offtopic => Topic started by: Mr_Mr_Mr on June 24, 2014, 04:08:46 am

Title: Any python wizards?
Post by: Mr_Mr_Mr on June 24, 2014, 04:08:46 am
I'm trying to find out how I can have python detect what directory the python file is in, but I just can't.

My code (Not really mine but it's just for an example):
Code: [Select]
import os

dirname = "C:\\Users\Derek\Desktop\Bob"
bob = os.listdir(dirname)
print(bob)

Basically what I'm wanting is for python to find out dirname on it's own when I move the .py file to a new directory (for example, if I move the python file to "C:\\Users\Derek\Desktop\Bob\Test" then I want it to automatically detect that.)

I'm using Miscellaneous operating system interfaces (https://docs.python.org/2/library/os.html).