Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path to current file depends on how I execute the program

Tags:

python

path

This is my Python program:

#!/usr/bin/env python

import os

BASE_PATH = os.path.dirname(__file__)
print BASE_PATH

If I run this using python myfile.py it prints an empty string. If I run it using myfile.py, it prints the correct path. Why is this? I'm using Windows Vista and Python 2.6.2.

like image 907
Deniz Dogan Avatar asked Sep 27 '09 15:09

Deniz Dogan


1 Answers

It's just a harmless windows quirk; you can compensate by using os.path.abspath(__file__), see the docs

like image 136
Alex Martelli Avatar answered Oct 02 '22 22:10

Alex Martelli