0

I think the title of the question is descriptive enough.

How can one find the location of the configuration file which is passed as an argument to a python script.

I would like to create a backup of the config file but copying it to another location.

2
  • 1
    Isn't the argument the location of the config? Commented Apr 18, 2016 at 14:22
  • Can post and example of how you supply this argument to your script on the command line? Commented Apr 18, 2016 at 14:29

1 Answer 1

2

You can join current working folder to the argument path to get an absolute path.

import os
import sys

if len(sys.argv) > 1:
    full_path = os.path.join(os.getcwd(), sys.argv[1])
    print(full_path)
Sign up to request clarification or add additional context in comments.

2 Comments

but this will not work for a config file which is not in the same directory with the script, will it?
It will. If you provide an absolute path, the result is the absolute path, whereas if you provide a relative path, it is relative to the current folder.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.