Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't open settings.json IOError: [Errno 2] No such file or directory: 'settings.json' #17

Closed
dgautsch opened this issue Mar 10, 2016 · 3 comments

Comments

@dgautsch
Copy link

I'm new to python so maybe i'm doing something wrong.

In the past when I've called open i have to specify the full path and I noticed the same thing with this bot.

with open('settings.json') as data:

That throws the following error in the console

IOError: [Errno 2] No such file or directory: 'settings.json'

importing os and adding the following fixes the issue:

import os
cwd = os.path.dirname(os.path.realpath(__file__))
with open(cwd + '/settings.json') as data:

Is this correct, or, am I doing something wrong?

@avery-crudeman
Copy link
Collaborator

That's weird. How are you running the script? Try using os.getcwd() to see what your working directory is.

IIRC, you shouldn't have to set the CWD to the location of the script unless you're running it from a different directory.

The default location should be the CWD, so if the script is in C:\directory and that's where you're running the script from, open() should be looking in that location for the file.

If CWD isn't the directory containing the script though, what you're doing fixes that problem fine.

@dgautsch
Copy link
Author

I was invoking the script via this command python src/main.py so that explains why this was happening. Thanks for the clarification avery-crudeman.

@toddrob99
Copy link
Contributor

This is fixed, should be closed.

mattabullock pushed a commit that referenced this issue Aug 4, 2017
…ghlights

Add baseball.theater link to highlights
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants