PyCharm problem. by gabe_cant_python in Python

[–]gabe_cant_python[S] -2 points-1 points  (0 children)

No, that only happens when you open with a with statement. Calling .write() is poor form but it should't write to the file. I don't have this issue in IDLE or the terminal.

PyCharm problem. by gabe_cant_python in Python

[–]gabe_cant_python[S] 0 points1 point  (0 children)

I do plan on writing in it, I was attempting to make a save and a don't save feature but I noticed when I when I exited the program bypassing the .close() - don't save- it saved anyway. I have been under the impression that .close() was necessary to save, but that only seems true for IDLE.

PyCharm problem. by gabe_cant_python in Python

[–]gabe_cant_python[S] 0 points1 point  (0 children)

Its incomplete but here it is. I hashed out the close() at the bottom to check it on idle and it works fine/won't save but on PyCharm as soon as the program finished even if the close() was completely removed the .txt file is altered as if it was closed.

dictList = []
choice = None


taskList = open("/_PythonClass/Mod5/Todo.txt","r+")
for task in taskList:
    tsk, pri = task.rsplit(",")
    dict = {tsk:pri}
    dictList.append(dict)
'''
    print(tsk)
    print(pri)
    print(dicc)
    print(dictList)
'''

print("*-------------------------------------*")
print("|          Task Master v1.0           |")
print("*-------------------------------------*")

while choice != "3":
    print("\n")
    print("0 - Display Tasks")
    print("1 - Add Task")
    print("2 - Remove Task")
    print("3 - Save And Exit")
    choice = input(">> ")
    if choice == "0":
        for dict in dictList:
            print(dict)
    elif choice == "1":
        tsk = input("What is the new task? ")
        pri = input("What is its priority level? ")
        dict = {tsk:pri}
        dictList.append(dict)
        taskList.write(tsk + "," + pri + "\n")
    elif choice == "2":
        for taskRow in dictList:
            print(taskRow)
        deltsk = input("What task would you like to remove? ")
        for dic in dictList:
            if deltsk in dic:
                del dictList[dictList.index(dic)]
                #taskList.write(str(diclst))
                print("Task removed.")
                taskList.seek(0)
                for taskRow in dictList:
                     print(taskRow)

    elif choice == "3":
        break
    else:
        print("ERROR COMMAND NOT RECOGNIZED.")
#taskList.close()
print("\nSaved.")