1

Basically, I want to call a python program from anywhere using shell so I added a shebang and copied it to /usr/local/bin with executable permission. The python program takes a command line argument which is the relative path of an input file.
I am stuck here, I have no idea what to do so that I can obtain the absolute path of the shell. I am assuming once I get the absolute path somehow, I can use sys.argv[1] to get the entered relative path of the file(which I will append to the absolute path of shell working directory) but please do correct me it won't work.

1 Answer 1

2

You can Print Working Directory via os.environ['PWD']. Content of your_script.py:

#!/usr/bin/python3.5

import os
print(os.environ['PWD'])

Usage:

sanyash@sanyash-ub16:/etc/nginx$ your_script.py 
/etc/nginx
sanyash@sanyash-ub16:/etc/nginx$
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.