Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV File Help
#5
With this in

print ("Time for the results!!!") #prints time for results
time.sleep(1) #adds a one second break
if amount_of_player_1_cards > amount_of_player_2_cards: #if the amount of cards player one has is bigger than the amount player two has
    print ("The winner, with " + amount_of_player_1_cards + " is....... " + username_1) #tells you the winner
    time.sleep(1) #adds a one seocnd break
    print (username_1 + " got the cards: ") #tells you what cards they got
    print (player_1_cards) #shows the cards
    time.sleep(1) #adds a one second break
    print ("That makes " + username_2 + " second place with " + amount_of_player_2_cards + " cards") #tells you who came 2nd
    with open("Card Game Scores.csv", "a+", newline = "") as save_score: #looking at what is in the file  
        save_score.write(player_1_results) #writes in the file what the users results were
        save_score.write("\n") #adds a space to make it clearer
        save_score.close() #saves and closes the file
else:
    print ("The winner, with " + amount_of_player_2_cards + " is....... " + username_2) #tells you the winner
    time.sleep(1) #adds a one second break
    print (username_2 + " got the cards: ") #tells you what cards they got
    print (player_2_cards) #shows the cards
    time.sleep(2) #adds a one second break
    print ("That makes " + username_1 + " second place with " + amount_of_player_1_cards + " cards") #tells you who came 2nd
    with open("Card Game Scores.csv", "a+", newline = "") as save_score: #looking at what is in the file  
        save_score.write(player_2_results) #writes in the file what the users results were
        save_score.write("\n") #adds a space to make it clearer
        save_score.close() #saves and closes the file
        
####################################################################################################
time.sleep(2) #adds a 2 second break
print ("This is how your scores compare to other winners of this game: ") #tells you this is how your socres compare to others
time.sleep(1) #adds a 2 second break
print ("This is these players most recent scores: ") #tells you these are there most recent scores
time.sleep(1) #adds a 1 second break
def first_seven_rows("Card Game Scores.csv"):
    with open(Card Game Scores.csv) as csvfile:
        reader = csv.reader(csvfile)
    for n, row in enumerate(reader):
        if n > 6:
            break
        print(f"{n}: {row}")  
I get the error

Error:
invalid syntax
the error is where I entered my filename I enter ("Card Game Scores.csv")

the error was highlighting the apostrophe



if I remove the apostrophes I get an invalid syntax highlighting the letter G on Card Game Scores.
Reply


Messages In This Thread
CSV File Help - by finndude - Apr-16-2020, 10:13 AM
RE: CSV File Help - by Larz60+ - Apr-16-2020, 01:59 PM
RE: CSV File Help - by finndude - Apr-16-2020, 03:02 PM
RE: CSV File Help - by Larz60+ - Apr-16-2020, 07:34 PM
RE: CSV File Help - by finndude - Apr-17-2020, 12:24 PM
RE: CSV File Help - by Larz60+ - Apr-17-2020, 09:28 PM
RE: CSV File Help - by finndude - Apr-17-2020, 09:53 PM
Organising CSV File - by finndude - Apr-18-2020, 12:34 PM
RE: Organising CSV File - by anbu23 - Apr-18-2020, 06:55 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020