Reputation: 15
I'm having trouble displaying information on the one line, I need it to display on one line and not separate lines. I want the variables player_name
, Outcome
and max_guesses
to be displayed on one line. This is the code I have:
f = open("Stats.txt", "a")
f.write( str(player_name) + "\n")
f.write( str(Outcome) + "\n")
f.write( str(max_guesses) + "\n")
f.close()
f = open("Stats.txt", "r")
print(f.read())
Upvotes: 0
Views: 53
Reputation: 16772
'\n'
being a string literal, also using with
you do not have to close the file in the end:
player_name = 'DirtyBit'
Outcome = 'Awesome'
max_guesses = '10'
with open("Stats.txt", "a") as fileObj:
fileObj.write(player_name + ' ' + Outcome + ' ' + max_guesses + ' ')
with open("Stats.txt", "r") as fileRead:
print(fileRead.read())
OUTPUT:
DirtyBit Awesome 10
Upvotes: 1