Kristof Pal
Kristof Pal

Reputation: 1026

How to find the location of the configuration file passed as argument to Python script?

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.

Upvotes: 0

Views: 86

Answers (1)

jpautom
jpautom

Reputation: 36

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)

Upvotes: 2

Related Questions