0

I learn python on Ubuntu system. There were errors shen I tried to read a file .

fw = open(outfile,"a") 
outfile = 'sougou/Reduced/C000008_pre.txt'
IOError: [Errno 2] No such file or directory: 'sougou/Reduced/C000008_pre.txt'
asked Jul 28, 2017 at 3:22
2
  • Either "sougou" does not exist or "sougou/Reduced" does not exist Commented Jul 28, 2017 at 3:24
  • Where are you calling Python script from? Or is this in an interactive terminal? Commented Jul 28, 2017 at 3:30

2 Answers 2

2

Without any additional information, I can see two possibilities here.

  1. The file you are trying to access doesn't exist.

  2. The path to the file is not correct relative to the location you are calling your Python script from.

Try providing the absolute path to the file, and see if that fixes your issue:

outfile = '/some/path/here/sougou/Reduced/C000008_pre.txt'
answered Jul 28, 2017 at 3:33
Sign up to request clarification or add additional context in comments.

Comments

0
  1. Maybe file sougou/Reduced/C000008_pre.txt does not exist
  2. The script does not be put in directory which contains sougou directory
  3. You should close file after open: fw.close() or using with open(outfile,"a") as fw: is better
answered Jul 28, 2017 at 9:23

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.