Python Forum

Full Version: cannot find file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am learning loading files by open().
I am sure I placed my text file in the same folder with my scripts.
But still get error:No such file or directory

I am using Python 3.5 with Eclipse.

Thanks,

L

import matplotlib.pyplot as plt
import csv

x = []
y = []

with open('example.txt','r') as csvfile:
    plots = csv.reader(csvfile, delimiter=',')
Above is my code
full traceback?
(Jan-11-2017, 07:14 AM)buran Wrote: [ -> ]full traceback?
Solved. Stupid mistake I made. I have to save the file as .txt explicitly.
Stupid mistakes are the best ones for learning what not to do.
Nobody fails if they never try!
(Jan-11-2017, 07:04 AM)landlord1984 Wrote: [ -> ]I am learning loading files by open().
I am sure I placed my text file in the same folder with my scripts.
But still get error:No such file or directory

I am using Python 3.5 with Eclipse.

Thanks,

L

import matplotlib.pyplot as plt
import csv

x = []
y = []

with open('example.txt','r') as csvfile:
    plots = csv.reader(csvfile, delimiter=',')
Above is my code

Might I add that you do not have to open a file using the 'r' argument. Files are opened automatically in read mode if nothing is specified.

EX:

with open(filename) as f_obj:
Curious - did you know you were answering a post from January?
(Apr-20-2017, 03:06 AM)Larz60+ Wrote: [ -> ]Curious - did you know you were answering a post from January?

bahaha i did not