英文:
To activate the telegram.exe
问题
I have problems in running the code below:
import pywinauto, time
from pywinauto.application import Application
from pywinauto.keyboard import send_keys
app = Application().start(cmd_line= "C:\Users\User\AppData\Roaming\Telegram Desktop\Telegram.exe" )
time.sleep(1)
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
please help me, thank you very much
I want to write code to activate telegram.exe on window 10 desktop
英文:
Hello I have problems in running the code below:
import pywinauto,time
from pywinauto.application import Application
from pywinauto.keyboard import send_keys
app = Application().start(cmd_line= "C:\Users\User\AppData\Roaming\Telegram Desktop\Telegram.exe" )
time.sleep(1)
------------------------------------------------------------------------
File "c:\Users\User\Desktop\Python\project", line 5
app = Application().start(cmd_line= "C:\Users\User\AppData\Roaming\Telegram Desktop\Telegram.exe" )
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
PS C:\Users\User\Desktop\Python>
please help me, thank you very much
I want to write code to activate telegram.exe on window 10 desktop
答案1
得分: 1
It's a simple basic Python error. You need a raw string: app = Application().start(cmd_line=r"C:\Users\User\AppData\Roaming\Telegram Desktop\Telegram.exe")
because \r
and \t
are special escape sequences: \R
is a new line caret return symbol, \T
is a tabulation one.
P.S. General advice about Telegram automation: please use Python API client instead of GUI automation. It is a much more reliable way. Also, Telegram desktop window doesn't provide many automation capabilities. It seems by design.
英文:
It's a simple basic Python error. You need raw string: app = Application().start(cmd_line=r"C:\Users\User\AppData\Roaming\Telegram Desktop\Telegram.exe")
because \r
and \t
are special escape sequences: \R
is a new line caret return symbol, \T
is a tabulation one.
P.S. General advise about Telegram automation: please use Python API client instead of GUI automation. It is much more reliable way. Also Telegram desktop window doesn't provide many automation capabilities. It seems by design.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论