5
import os,pdb
import sys
print os.path.dirname(os.path.realpath(__file__))
pdb.set_trace()
os.chdir('../bci_framework')

Output:

D:\baseline\BCI-Comparison-Framework\bci_framework
WindowsError: (2, 'The system cannot find the file specified', '../bci_framework')

Why? The folder is present!

2
  • What's your current path? '..' on UNIX-like systems means "go back a folder", to my knowledge. Commented Sep 25, 2015 at 15:19
  • Confirmed that the same is true for windows: 7tutorials.com/command-prompt-how-use-basic-commands. Perhaps try changing the ".." to "." if you're meaning to refer to your current directory. Commented Sep 25, 2015 at 15:24

1 Answer 1

6

The file is in the directory bci_framework, which is why printing out it's path shows you that directory, but you aren't. Wherever you are, it doesn't have bci_framework as a sibling.

Print out os.getcwd() to determine your current location. Any relative paths to chdir will be relative to that location, not to the location of the file.

For example, if you are in the stackoverflow directory below, and run python ./abhishek/bci_framework/my_file.py, your current directory is stackoverflow. Going up one directory will not contain the bci_framework directory.

stackoverflow/
    davidism/
    abhishek/
        bci_framework/
            my_file.py
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.