2

I am learning Python 3 at the moment, and I have a problem with opening a file provided as a function parameter.

This is my code:

def make_list_from_file(file_name):

    with open(file_name,"r") as provided_file:
        temp_list = [line.strip() for line in provided_file]
    detailed_list = [ item.split("\t") for item in temp_list ]
    return detailed_list

make_list_from_file(game_stat.txt)

This gives me:

NameError: name 'Game_Stat' is not defined. 

The file is in the same directory. I would be grateful for any help.

2
  • 3
    pass a string to the function, like this make_list_from_file("game_stat.txt") Commented Jan 6, 2018 at 18:13
  • look at the csv module from the stdlib! Commented Jan 6, 2018 at 18:38

2 Answers 2

2
make_list_from_file(game_stat.txt)

strings should be enclosed with single (') or double (") quotes.

So:

make_list_from_file("game_stat.txt")
Sign up to request clarification or add additional context in comments.

Comments

0

Change this line:

with open(file_name,"r") as provided_file:

to :

with open(file_name + '.txt',"r") as provided_file:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.