I'm really sorry if this question has been asked before, but I can't seem to find the solution to this error anywhere for my case.
I have a text file with screen coordinates (x and y, separated by a new line), and I want to read the file, and store every line of the file onto an two separate arrays - one for X, and one for Y.
I then want to use pyautogui.moveTo()
to move to the two x and y coordinates, then click (I haven't done any of that yet).
The variable actionNumber
simply acts like i
in a for loop, to count which line we're on in the text file.
How can I create the two arrays (dataX[] and dataY[]) in python that can be read through mainLoop()
, and then store a line of data from the file in dataX[actionNumber]
and then the next line of the file into dataY[actionNumber]
?
Here is my code, it is pretty simple:
actionNumber = 0
dataX = []
dataY = []
f = open("track_cursor_position_log.txt", "r")
#print(f.read())
def mainLoop():
#I need to store the first line of the file into dataX, then the second into dataY, then the 3rd into dataX, and so on...
actionNumber = actionNumber + 1
mainLoop()
mainLoop()
Here are the errors I get:
Traceback (most recent call last):
File "C:/Users/devel/Downloads/python-imagesearch-master/python-imagesearch-master/ClickAgentTest.py", line 17, in <module>
mainLoop()
File "C:/Users/devel/Downloads/python-imagesearch-master/python-imagesearch-master/ClickAgentTest.py", line 13, in mainLoop
actionNumber = actionNumber + 1
UnboundLocalError: local variable 'actionNumber' referenced before assignment
Here is a small snippet of the data in the file track_cursor_position_log.txt
, just so you can get what I'm talking about:
1858
1129
1292
1165
927
1287
1501
461
1567
709
2298
1049
1473
1244
2511
1722
I once more apologise if this is a noob question, but I am more of a c++/JS coder, and I haven't used python in a while...
Thank you very much to everyone who can help out!