Как пройти через csv и иметь возможность вернуться на шаг назад или продолжить построчно? - PullRequest
0 голосов
/ 30 октября 2018

Я пытаюсь найти время для пользователя. Допустим, они вводят 13 (минут), мой код прокручивает CSV и находит каждую строку, которая имеет 13 в колонке времени. Затем он печатает строку по одному за раз. Я не знаю, как позволить пользователю иметь возможность вернуться к предыдущему шагу? Мой код в настоящее время просто меняет порядок csv, начинается снизу, даже если строки не являются выбранными 13-минутными строками.

Я новичок, поэтому постарайтесь объяснить как можно проще ... Спасибо

Пожалуйста, смотрите код:

def time():

while True:
    find = input("Please enter a time in minutes(rounded)\n"
                "> ")

    if len(find) < 1:
        continue
    else:
        break


print("Matches will appear below\n"
      "If no matches were made\n"
      "You will return back to the previous menu.\n"
      "")

count = -1

with open("work_log1.csv", 'r') as fp:
    reader = csv.DictReader(fp, delimiter=',')
    for row in reader:
        count+=1
        if find == row["time"]:
            for key, value in row.items(): # This part iterates through csv dict with no problems
                print(key,':',value)

                changee = input("make change? ")
                if changee == "back":                    # ISSUE HERE******
                    for row in reversed(list(reader)):   # I'm trying to use this to reverse the order of whats been printed
                        for key, value in row.items():   # Unfortunately it doesnt start from the last item, it starts from
                            print(key,':',value)         # The bottom of the csv. Once I find out how to iterate through it
                                                         # Properly, then I can apply my changes
            make_change = input("make change?  or go back")

            if make_change == 'y':
                new_change = input("input new data: ")
                fp = pd.read_csv("work_log1.csv")
                fp.set_value(count, "time", new_change) # This part makes the changes to the row i'm currently on
                fp.to_csv("work_log1.csv", index=False)




        print("")
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...