Azula
Azula

Reputation: 16

pyautogui not writing text properly

I am trying to automatically open idle and write a piece of code using pyautogui but putting the \n character is showing unusual behavior.....

codestring='def Split(mainstring,separator_string):\n\ta=mainstring\n\tb=separator_string\n\tlst1=[]\n\tlst2=[c1 for c1 in range(len(a)) if a[c1]==b]\n\tlst3=[c2 for c2 in range(len(a)) if a[c2]==b]\n\tlst2.insert(0,0)\n\tprint(lst2)\n\tfor i in range(len(lst3)+1):\n\t\tif i%2==1:\n\t\t\tlst2.insert(i+1,lst2[i]+1)\n\tlst2.insert(len(lst2)-1,lst2[len(lst2)-1]-1)\n\tii=-2\n\tjj=-1\n\twhile ii<=len(lst3)-2 and jj<=len(lst3)-2:\n\t\tii+=2\n\t\tjj+=2\n\t\tlst1.append(a[lst2[ii]:lst2[jj]])\n\tlst1.append(a[lst2[len(lst2)-1]:])\n\treturn lst1\nprint(Split("hello world. Byebye world. Shame on you world. OK world. No world. Please world. Yes world.",\' \'))'
import subprocess as sp
import time
import pyautogui as ui

sp.run('cmd /c start /max cmd.exe')
time.sleep(3)
ui.write(r'idle C:\User\USERS\Documents\split.py',interval=0.023)
ui.press('enter')
time.sleep(6)
ui.write('#the split function\n\n',interval=0.1)
ui.write(codestring,interval=0.2)

the output is:

#the split function

def Split(mainstring,separator_string):
        a=mainstring
            b=separator_string
                lst1=[]
#^^^^^^^^^^^^^^^^

i am a newbie in pyautogui .This is a humble question........ please help me

Upvotes: 0

Views: 942

Answers (1)

mukund ghode
mukund ghode

Reputation: 262

with python -m idlelib <script_to_edit> you will be able to open and edit the script with idle. So, change

ui.write(r'idle C:\User\USERS\Documents\split.py',interval=0.023)

to

ui.write(r'python -m idlelib C:\User\USERS\Documents\split.py',interval=0.023)

Upvotes: 1

Related Questions