tags:

views:

37

answers:

1

I have a Python script, named script.py. It's located on ~/scripts/script.py.

I have an alias in ~/.bash_aliases:

alias script='python ~/scripts/script.py'

I have some directories in a checked out repository, for example:

~/repository/project_dir/module_name/

I run on my terminal, inside ~/repository/project_dir/module_name/, the script alias I created. This script has a print statement printing the directory from where the script.py was run, but I want it to print from where it was called. How do I do it?

(Now, I'm using os.path.abspath(sys.argv[0]) and it prints ~/scripts/script.py instead of ~/repository/project_dir/module_name/)

+3  A: 
import os
print os.getcwd()

For more details, check out the python docs.

sharth
cwd = current working dir
ZeissS
Thats correct... I've used this command in the past, but I didn't work.. I think I did something wrong at that time. Thanks for the answer, it works as intended! (But it's better to use os.getcwdu to handle unicode).
Somebody still uses you MS-DOS