2

I'm working on a project at the end of a book I read for Python, so in case this hasn't given it away for you, I'm still quite new to this.

I'm trying to use the open command to open a file that I know exists. I know that the code understands the file is there, because when I switch over to write mode, it clears my text file out, telling me that it can find the file but it just won't read it. Why is this happening? Here's the code-

openFile = open('C:\\Coding\\Projects\\Python\\One Day Project\\BODMAS\\userScores.txt', 'r') def getUserPoint(userName): for line in openFile: split(',') print(line, end = "") 

I've tried a few variations where my openFile function is a local variable inside getUserPoint(), but that didn't make a difference either.

Editing because I missed a vital detail — the userScores.txt file is laid out as follows:

Annie, 125 

The split() function is supposed to split the name and the score assigned to the name.

2
  • 4
    Probably erroring out on split(',') which isn't a function. Put some code there that will do something. Commented Aug 11, 2016 at 1:25
  • Opening the file in write mode will work regardless of whether the file already exists or not, so it doesn't imply what you said. Commented Aug 11, 2016 at 2:06

1 Answer 1

1

Your function isn't valid Python, as split isn't a globally defined function, but a built-in function of the type str. Try changing your function to something like this.

def getUserPoint(name): for line in openFile: line_split = line.split(",") print(line_split, end = "") 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.