Python 3.x 在python中打开文件时需要一个整数错误
我试图用python打开一个文件,但我一直得到错误“需要一个整数” 我的代码:Python 3.x 在python中打开文件时需要一个整数错误,python-3.x,text-files,Python 3.x,Text Files,我试图用python打开一个文件,但我一直得到错误“需要一个整数” 我的代码: print("This is console module") import random def randomNumber(myFile): times=0 print("Generating numbers...") while times != 10: random=random.randint(1, 100)
print("This is console module")
import random
def randomNumber(myFile):
times=0
print("Generating numbers...")
while times != 10:
random=random.randint(1, 100)
print("\nNumber generated: "+str(random))
myFile.write(random)
times+1
myFile.close()
print("Done")
myFile = open("NUMBERS.TXT", "a", "wt", "rt")
randomNumber(myFile)
myFile.close()
我想让它把随机数打印到一个文件中你能缩进你的代码吗?…然后开始使用我学过的那样打开文件的方法。@ThePlumbo179很好。。。语言随着时间的推移而变化,你做事的方式也需要相应地改变。多年来,将
与
一起使用一直是打开文件的首选方式。教你不用它打开文件的人可能跟不上Python的发展。不,我是一周前学的。不要粗鲁。