I have a save function in my Python program that looks like this:
def Save(n): print("S3") global BF global WF global PBList global PWList print(n) File = open("C:\KingsCapture\Saves\\" + n + "\BF.txt", "w") pickle.dump(BF, File) File = open("C:\KingsCapture\Saves\\" + n + "\WF.txt", "w") pickle.dump(WF, File) File = open("C:\KingsCapture\Saves\\" + n + "\PBList.txt", "w") pickle.dump(PBList, File) File = open("C:\KingsCapture\Saves\\" + n + "\PWList.txt", "w") pickle.dump(PWList, File)
Here n is "1".
I get an error message:
File "C:/Python27/KingsCapture.py", line 519, in Save File = open("C:\KingsCapture\Saves\\" + n + "\BF.txt", "w") TypeError: an integer is required
Performing the same load inside the shell, I get no errors:
>>> File = open("C:\KingsCapture\Test\List.txt", "r") >>> File = open("C:\KingsCapture\Test\List.txt", "w") >>> n = "1" >>> File = open("C:\KingsCapture\Saves\\" + n + "\BF.txt", "r") >>> File = open("C:\KingsCapture\Saves\\" + n + "\BF.txt", "w")
Why does this have a problem?
source share