在python中,如何粘贴代码块
我正在尝试编写一个python脚本,它允许我粘贴大块代码。现在我可以让系统从变量粘贴文本。然而,我想粘贴的代码很长,并且有很多特殊字符。有什么办法可以让我轻松解决这个问题吗 这是我目前掌握的代码在python中,如何粘贴代码块,python,tkinter,clipboard,pyautogui,Python,Tkinter,Clipboard,Pyautogui,我正在尝试编写一个python脚本,它允许我粘贴大块代码。现在我可以让系统从变量粘贴文本。然而,我想粘贴的代码很长,并且有很多特殊字符。有什么办法可以让我轻松解决这个问题吗 这是我目前掌握的代码 import pyautogui from tkinter import Tk root = Tk() root.withdraw() result = 'Text to Paste' x, y = pyautogui.position() pyautogui.click(x, y) pyautogu
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.