0

I'm using VSCode on a mac and I can't figure out why I'm getting

FileNotFoundError: [Errno 2] No such file or directory: 'flying_circus_cast.txt' 

with the following snippet of code. The text file is in the same directory as the python file.

I've also tried ./flying_circus_cast.txt too but I get the same error

def create_cast_list(filename):
    cast_list = []
    #use with to open the file filename
    #use the for loop syntax to process each line
    #and add the actor name to cast_list
    with open('flying_circus_cast.txt', 'r') as f:
        print(f.read())

    return cast_list

cast_list = create_cast_list('flying_circus_cast.txt')
for actor in cast_list:
    print(actor)
Cohan
  • 4,384
  • 2
  • 22
  • 40
CodeHappy
  • 71
  • 2
  • 10

0 Answers0