Jump to content

Hello,

I have tried a few things to get the full path of a file, but no luck.

 

This is what I use now but it adds a +a or +r at the end which makes it look for etc file.txt/+a

 

script_dir = os.path.dirname(__file__)
data = json.load(open(os.path.join(script_dir, 'config.json')))

How can I solve this? I need it for crontab so it runs in the correct location, and the location may change so it can't be hard coded.

Back-end developer, electronics "hacker"

Link to comment
https://linustechtips.com/topic/874333-python-full-path/
Share on other sites

Link to post
Share on other sites

Daily Driver:

CPU - Dual X5670 | GPU - GTX 750 Ti | CASE - HP DL380 G7 | RAM - 128GB Samsung 1366 DDR3 ECC | STORAGE - 8 x 146GB 15K RPM HDD

Work Horse:

CPU - Quad E7-4870 | GPU - Quad Tesla M2090 | CASE - HPDL580 G7 | RAM - 128GB Samsung 1366 DDR3 ECC | STORAGE - 2 x 256GB Samsung 950 EVO SSD

 

Link to comment
https://linustechtips.com/topic/874333-python-full-path/#findComment-10831993
Share on other sites

Link to post
Share on other sites

Actually, you should be able to plop it right here:

 

script_dir = os.path.dirname(os.path.abspath(__file__))
data = json.load(open(os.path.join(script_dir, 'config.json')))

Daily Driver:

CPU - Dual X5670 | GPU - GTX 750 Ti | CASE - HP DL380 G7 | RAM - 128GB Samsung 1366 DDR3 ECC | STORAGE - 8 x 146GB 15K RPM HDD

Work Horse:

CPU - Quad E7-4870 | GPU - Quad Tesla M2090 | CASE - HPDL580 G7 | RAM - 128GB Samsung 1366 DDR3 ECC | STORAGE - 2 x 256GB Samsung 950 EVO SSD

 

Link to comment
https://linustechtips.com/topic/874333-python-full-path/#findComment-10833218
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×