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'
-
Either "sougou" does not exist or "sougou/Reduced" does not existanthony sottile– anthony sottile2017年07月28日 03:24:26 +00:00Commented Jul 28, 2017 at 3:24
-
Where are you calling Python script from? Or is this in an interactive terminal?Andrew Guy– Andrew Guy2017年07月28日 03:30:37 +00:00Commented Jul 28, 2017 at 3:30
2 Answers 2
Without any additional information, I can see two possibilities here.
The file you are trying to access doesn't exist.
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
Andrew Guy
10.1k3 gold badges31 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
- Maybe file
sougou/Reduced/C000008_pre.txtdoes not exist - The script does not be put in directory which contains
sougoudirectory - You should close file after open:
fw.close()or usingwith open(outfile,"a") as fw:is better
answered Jul 28, 2017 at 9:23
tuannv256
5011 gold badge4 silver badges10 bronze badges
Comments
lang-py