我在这里有一个简单的问题。我有一个txt文件中的两个数字,我正在尝试创建一个方法,可以在我的代码中为txt文件中的这两个数字更改两个变量。在Python中加载一个txt文件
这里是我的方法:
def loadCoords(cordX, cordY):
i=0;
f1 = open('continue.txt', "r")
f2 = open('continue.txt', "r")
f1.readline();
while i<2:
f2.readline();
i=i+1;
#already tested>>> cord=f.readline() xD
#also tried to put another names for the cordX and cordY here inside xD
cordY=f2;
cordX=f1;
return cordX;
return cordY;
这里是我打电话的方法:
if evento.type == pygame.KEYDOWN:
if evento.key == pygame.K_a:
print('GAME BEGIN')
GAME_BEGIN = True
loadCoords(cordX,cordY);
有人可以帮助?
什么是你所得到的错误? –
没有人,它只是无法读取f1和f2文件,coordX和Y打印0和0,我已经在开始声明的数字。 – Aury0n
可能的重复[如何在Python中将文本文件读入字符串变量](http://stackoverflow.com/questions/8369219/how-do-i-read-a-text-file-into-a-字符串变量在Python中) – DeepSpace