Aury0n Aury0n - 28 days ago 9
Python Question

Load a txt file in Python

I have a simple question here. I have two numbers in a txt file and I am trying to create a method that can change two variables in my code for those two numbers in the txt file.

Here is my method:

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;


Here is where I am calling the method:

if evento.type == pygame.KEYDOWN:
if evento.key == pygame.K_a:
print('GAME BEGIN')
GAME_BEGIN = True
loadCoords(cordX,cordY);


Someone could help?

Answer

forget, it is done, hahaha def loadCoords(): f1 = open( "continue.txt", "r") text=f1.read() num_list=text.split() print (num_list) cordX=num_list[0] print(cordX) cordY=num_list[1] f1.close()
return cordX,cordY