material serurubele
material serurubele

Reputation: 11

IOError: Errno 2 No such file or directory python

i hav confirmed that "apples.txt" do exist.what is wrong with my code?

   def Loadfile(fileName):
        myfile=open(fileName,'r')
        next(myfile)
        for line in myfile:
            linesplit=line.split()
            print line

    print Loadfile('apples.txt')

Upvotes: 1

Views: 3262

Answers (2)

BREI
BREI

Reputation: 111

arq = open('C:\\python2.6\\projetos\\test\\list.txt', 'r')
texto = arq.readlines()
for linha in texto:
    print(linha)
arq.close()

Upvotes: 0

Cory Kramer
Cory Kramer

Reputation: 117856

The file probably isn't in your working directory. Either change your working directory to where apples.txt is located, or provide a full path to the file such as 'C:\\folder\\subfolder\\apples.txt'

Upvotes: 3

Related Questions