[Python] Python script continuously repeats the first if - else statement

Discussão em 'Python' iniciado por Stack, Dezembro 6, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to have this script find if the file 'save_the_world.txt' exists and print a response accordingly, and create the file if it does not exist. It also sets up the logger. After doing that it is supposed to run another script and then stop. Instead, it prints the response continuously and does not move on.

    import os, logging, sys

    saveFilePath = 'save_the_world.txt'

    logging.basicConfig(filename='game.log', level='DEBUG',
    format='%(asctime)s - %(levelname)s - %(message)s')

    if os.path.exists(saveFilePath):
    print("Save file found! Welcome back.")
    newPlayer = False
    else:
    with open(saveFilePath, 'x') as f:
    f.write("Save file placeholder text.")
    print("Welcome, new player (or deleter of save files)!")
    newPlayer = True

    os.system('python core\login.py')


    i attempted to add break to the if-statement output lines, no change. I have not found any solutions to my specific problem online.

    edit: this file is called start_game.py edit2: changing import start_game to from start_game import newPlayerhad no effect.

    Continue reading...

Compartilhe esta Página