December 27, 2024, 07:04:30 am

Author Topic: Any python wizards?  (Read 2015 times)

0 Members and 1 Guest are viewing this topic.

Mr_Mr_Mr

  • Veteran
  • Champion Member
  • ***
  • Posts: 3079
    • View Profile
Any python wizards?
« 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.
« Last Edit: June 24, 2014, 05:55:04 am by Mr_Mr_Mr »

---><--- Click the monkey