-2

I have the below function which asks the user for a file and then returns the lines in that file (excluding the lines that contain a - symbol).

However I have an error with the function. While it does ask for input, this is not passed into the function. Would anyone be able to help me with where I went wrong? Thank you

filename = input('input the filename: ')

def read_from_file(filename):
    with open(filename) as file:
        content = [line for line in file if '-' not in line]
    return content
TC1111
  • 89
  • 8

1 Answers1

2

You did not call the function! Add this line to your code:

content = read_from_file(filename)

And you will be good. Your code should be something like this:

filename = input('input the filename: ')

def read_from_file(filename):
    with open(filename) as file:
        content = [line for line in file if '-' not in line]
    return content

content = read_from_file(filename)

Good luck!

alift
  • 1,855
  • 2
  • 13
  • 28