通過re模組寫乙個文字查詢小工具

2021-09-02 18:13:21 字數 2629 閱讀 1066

#_*_ conding:utf-8 _*_

from tkinter import filedialog

from tkinter import *

from tkinter.scrolledtext import scrolledtext

import io

import re

def open_file(route):

global file

file = io.open('%s'%route, 'r', encoding='utf-8').read()

text1.delete('1.0', end) # 寫入內容

text1.insert('1.0', file)

def data1():

global file

pattern = r'.*?}'

dotall = re.compile(pattern, re.dotall) # dotall標誌,就可以讓( 點)匹配所有字元,不再排除換行符了

a = re.findall(dotall, file)

print(a)

print(file)

text1.delete(1.0, end)

file1 =

pattern = r'("id":.*?),.*?(%s)'%str(text2.get(1.0,end)).strip()

dotall1 = re.compile(pattern, re.dotall)

for i in range(len(a)):

a1 = re.findall(dotall1, a[i])

for arg in range(len(file1)):

if len(file1[arg]):

text1.insert(1.0, str(file1[arg]) + '\n\r')

def data2():

global file

pattern = r'.*?}'

dotall = re.compile(pattern, re.dotall) # dotall標誌,就可以讓( 點)匹配所有字元,不再排除換行符了

a = re.findall(dotall, file)

print(a)

print(file)

text1.delete(1.0, end)

file1 =

pattern = r'"ecsname":.*?]'

dotall1 = re.compile(pattern, re.dotall)

for i in range(len(a)):

a1 = re.findall(dotall1, a[i])

for arg in range(len(file1)):

if len(file1[arg]):

text1.insert(1.0, str(file1[arg]).replace(' ','').replace('\\n','')+'\n\r')

def open(): # 開啟檔案寫入文字中

filetypes = [

("all files", '*'),

("python files", '*.py', 'text'),

("text files", '*.txt', 'text'),

("config files", '*.conf', 'text')

]fobj1 = filedialog.askopenfile(filetypes=filetypes)

open_file(fobj1.name.replace('/','\\\\'))

if fobj1:

text.delete(1.0, end) # 寫入名字和路徑

text.insert(1.0, fobj1.name)

#監控介面

window = tk()

window.title('查詢工具')

window.geometry('350x470')

window.resizable(0,0)

frame1= frame(window)

button1=button(window,text='開啟',width=5,height=1,command=open)

button1.place(x=1,y=1)

text=text(window,width=30,height=2)

text.place(x=50,y=1)

text1=scrolledtext(window,width=47,height=30)

text1.place(x=1,y=80)

button2=button(window,text='查詢id',width=5,height=1,command=data1)

button2.place(x=1,y=40)

text2=text(window,width=10,height=2)

text2.place(x=55,y=40)

button2=button(window,text='查詢escname',width=10,height=1,command=data2)

button2.place(x=200,y=40)

mainloop()

開始寫乙個核心模組

從hello world開始,乙個完整的核心模組helloword.c如下 include module init 和 module exit 的標頭檔案 include 這個標頭檔案包含了許多符號與函式的定義,這些符號與函式多與載入模組有關 module license dual bsd gpl ...

Linux 寫乙個簡單的模組

1.建立乙個目錄 mkdir zhu cd zhu vim hello.c 編寫乙個名為hello的檔案 2.hello.c include 所有模組都需要的標頭檔案 include static int hello init void static void hello exit module i...

sql查詢,nolock寫還是不寫,這是乙個問題

在做過的很多專案中,發現大家不管對什麼表,逢select必定加上nolock 或者with nolock 好像已經是制度化的一種東西。有領導高人解釋說加上nolock可以提高查詢速度,不影響對資料表的其他併發操作。但是真有必要每個查詢都加nolock嗎?個人認為加不加nolock還是值得我們根據實際...