如何从剪贴板中读取数据并将其作为值传递给python中的变量?
例如:
我将通过按ctrl + c或右键单击复制一些数据{例如:200}.并将其传递给变量.
c = 200
..can any1告诉我怎么做?
首先感谢帮助我移动文件和帮助我使用tcl脚本.
小疑问我有python代码..如下所示..
import os
import shutil
data =" set filelid [open \"C:/Sanity_Automation/Work_Project/Output/smokeTestResult\" w+] \n\
puts $filelid \n\
close $filelid \n"
path = "C:\\Sanity_Automation\\RouterTester900SystemTest"
if os.path.exists(path):
shutil.rmtree('C:\\Sanity_Automation\\RouterTester900SystemTest\\')
path = "C:\\Program Files (x86)"
if os.path.exists(path):
src= "C:\\Program Files (x86)\\abc\\xyz\\QuickTest\\Scripts\\RouterTester900\\Diagnostic\\RouterTester900SystemTest"
else:
src= "C:\\Program Files\\abc\\xyz\\QuickTest\\Scripts\\RouterTester900\\Diagnostic\\RouterTester900SystemTest"
dest = "C:\\Sanity_Automation\\RouterTester900SystemTest\\"
shutil.copytree(src, dest)
log = open('C:\\Sanity_Automation\\RouterTester900SystemTest\\RouterTester900SystemTest.app.tcl','r+')
log_read=log.readlines()
x="CloseAllOutputFile"
with open('C:\\Sanity_Automation\\RouterTester900SystemTest\\RouterTester900SystemTest.app.tcl', 'a+') as fout:
for line in log_read:
if x in line:
fout.seek(0,1)
fout.write("\n")
fout.write(data)
Run Code Online (Sandbox Code Playgroud)
此代码用于将文件从一个位置复制到另一个位置,在特定文件中搜索关键字并将数据写入文件正在运行...
我的疑问是每当我写的..它写到文件末尾而不是当前位置...
示例:说..我将文件从程序文件复制到sanity文件夹,并在其中一个复制文件中搜索单词"CloseAllOutputFile".当找到单词时,它应该在该位置插入文本而不是文件末尾.
例如,考虑一个文件“abc.txt”具有以下内容
{apple_Text "1"}
{banana_Text "2"}
{orange_Text "3"}
Run Code Online (Sandbox Code Playgroud)
现在,我想在该文件中搜索“apple_Text”关键字,如果找到它应该在其中打印第二列值,即“1”。我可以知道如何在 Tcl 中做到这一点吗?