在python中我如何粘贴代码块

问题描述

我正在尝试编写一个Python脚本,该脚本将允许我粘贴大量代码。现在,我可以使系统粘贴变量中的文本。但是,我要粘贴的代码很长,并且其中包含许多特殊字符。我有什么办法可以轻松解决这个问题?

这是我目前拥有的代码

import pyautogui
from tkinter import Tk
root = Tk()
root.withdraw()
result = 'Text to Paste'

x,y = pyautogui.position()
pyautogui.click(x,y)
pyautogui.typewrite(result)

解决方法

import pyautogui,time,pyperclip # pyperclip used for copy and paste

var1 = ("words block here") # you replace this with large words

pyautogui.click(x=399,y=600) # click where you want to paste "var1" value

time.sleep(1) # delay

pyperclip.copy(var1)  # variable that stores your pasting block

time.sleep(1) # delay

pyautogui.hotkey("ctrl","v") # and paste it with pyautogui.