0

I have this simple code

def main():
    ff = open("../text_learning/test_email.txt", "r")

when I try to run it in Visual Studio code I get this error:

IOError: [Errno 2] No such file or directory: '../text_learning/test_email.txt'

But when I run it from cmd it works.

Any idea why the Visual Studio code is causing troubles?

The dir tree:

└───ud120-projects
    ├───.vscode
    ├───choose_your_own
    ├───datasets_questions
    ├───decision_tree
    ├───evaluation
    ├───feature_selection
    ├───final_project
    │   └───emails_by_address
    ├───k_means
    ├───naive_bayes
    ├───outliers
    ├───pca
    ├───regression
    ├───svm
    ├───text_learning
    ├───tools
    └───validation

The Visual Studio code is opened to the root directory (ud120-projects).

3
  • 1
    Try removing the ../ Commented Apr 3, 2017 at 17:11
  • 1
    maybe try to make it relative to the module using os.path.dirname(__file__) Commented Apr 3, 2017 at 17:15
  • Thank you guys, Wright its worked. im still learning python so sorry for the dumb question Commented Apr 3, 2017 at 17:24

1 Answer 1

1

Just change the path to

open("text_learning/test_email.txt", "r")

instead of

open("../text_learning/test_email.txt", "r")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.