I have been trying to solve this issue. I have written:
file.write("pyautogui.write(" + "'" + textEntry + "'" + ")")
but in the file that is written to, the following is written:
pyautogui.write('test
')
I want it all to be on one line. Does anyone know the cause for this? I have tried fixing it, but to no avail.
>Solution :
What’s happening here is that the textEntry variable likely has a \n character at the end of it, a simple way to solve that is by using strip(). Also, it is generally recommended to use f-Strings instead of doing the + each time. A solution is as follows:
file.write(f"pyautogui.write('{textEntry.strip()}')")