PowerShell实现简单的搜索地区功能
import os
from tkinter import Tk
from tkinter import Label
from tkinter import Button
from tkinter import Entry
from tkinter import StringVar # public Dictionary<string, string> GenerateAreaDict(string filePath) {
# Dictionary<string, string> areaDict = new Dictionary<string, string>(); # if (File.Exists(filePath)) {
# string[] areaCode = File.ReadAllLines(filePath); # foreach (string code in areaCode) {
# areaDict.Add(code.Substring(0, 6), code);
# }
# } # return areaDict;
# } def generateAreaDict():
text = '' with open(fullFilePath, 'r') as file:
text = file.read() text = text.replace(' ', '').replace('\t', '').split('\n') for line in text:
if len(line) > 0:
area[line[:6]] = line[6:] # public string[] Search(string areaName, Dictionary<string, string> areaDict) {
# List<string> areaIndex = new List<string>(); # foreach (KeyValuePair<string, string> kvp in areaDict) {
# if (kvp.Value.Contains(areaName)) {
# areaIndex.Add(kvp.Key);
# }
# } # return areaIndex.ToArray();
# } def search():
name = entryVar.get().replace(' ', '') if len(name) > 0:
result.clear() for key, value in area.items():
if value.find(name) != -1:
result.append([key, value]) if len(result) > 0:
deepSearch()
else:
labelVar.set('Not find.') # public string[] DeepSearch(string[] areaIndex, Dictionary<string, string> areaDict) {
# List<string> areaInfo = new List<string>();
# string temp = ""; # foreach (string index in areaIndex) {
# temp = ""; # if (index.Substring(2, 2).Equals("00")) {
# temp += areaDict[index];
# } else if (index.Substring(4, 2).Equals("00")) {
# string i = index.Substring(0, 2) + "0000"; # if (areaDict.ContainsKey(i)) {
# temp += (areaDict[i] + "\t");
# }
# temp += areaDict[index];
# } else {
# string i = index.Substring(0, 2) + "0000";
# string j = index.Substring(0, 4) + "00"; # if (areaDict.ContainsKey(i)) {
# temp += (areaDict[i] + "\t");
# }
# if (areaDict.ContainsKey(j)) {
# temp += (areaDict[j] + "\t");
# }
# temp += areaDict[index];
# } # areaInfo.Add(temp);
# } # return areaInfo.ToArray();
# } def deepSearch():
for r in result:
code = r[0] if code[4:] != '':
key = code[:4]+''
if key in area:
r.append(key)
r.append(area[key]) key = code[:2]+''
if key in area:
r.append(key)
r.append(area[key]) elif code[2:] != '':
key = code[:2]+''
if key in area:
r.append(key)
r.append(area[key]) showResult() def showResult():
text = '' for r in result:
line = '' for i in range(1, len(r), 2):
line = r[i] + ' ' + line text = text + line + '\n' labelVar.set(text) def searchCallback(event):
search() # public class AreaSearchToolApp {
# public void Run() {
# string filePath = "AreaCode.txt";
# string areaName = "萧山"; # Dictionary<string, string> areaDict = GenerateAreaDict(filePath); # string[] areaIndex = Search(areaName, areaDict);
# string[] areaInfo = DeepSearch(areaIndex, areaDict);
# } window = Tk()
window.title('Search Tool')
window.geometry('350x200') labelVar = StringVar() # should after Tk() function
entryVar = StringVar()
area = {}
result = []
cwd = os.getcwd()
filename = 'AreaCode.txt'
fullFilePath = os.path.join(cwd, filename) Label(window, textvariable=labelVar, justify='left').pack(fill='both', expand='yes') if os.path.exists(fullFilePath) and os.path.isfile(fullFilePath):
generateAreaDict() Entry(window, textvariable=entryVar).pack(fill='x', padx=10, pady=5)
window.bind('<Return>', searchCallback)
Button(window, text='Search', command=search).pack(fill='x', padx=10, pady=5)
else:
labelVar.set('Please put ' + filename + ' under ' + cwd + '.') window.mainloop()
https://files.cnblogs.com/files/howld/SearchTool.zip
PowerShell实现简单的搜索地区功能的更多相关文章
- 基于Vuejs的搜索匹配功能
最近一直在看vue,查了很多资料,看了很多文档和博客,大概半知半解了,然后利用所理解的知识写了一个简单的搜索匹配功能. 大概长这个样子: <!DOCTYPE html> <htm ...
- jQuery实现简单前端搜索功能
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Vue2.0实现1.0的搜索过滤器功能
Vue2.0删除了很多1.0的比较实用的过滤器,如filterBy,orderBy.官方文档给了通过计算属性实现1.0搜索过滤器功能,自己又加入了大小写通用检索功能,比较简单,学一下. <bod ...
- 使用 JavaScript 实现简单候选项推荐功能(模糊搜索)【收藏】【转】
当我们使用 Google 等搜索功能时,会出现与搜索内容有关的候选项.使用 JavaScript 搜索字符串,通常会使用 indexOf 或者 search 函数,但是非常僵硬,只能搜索匹配特定词语. ...
- JavaScript实现搜索联想功能
-.虽然Jquery已经有了一个完整的包 实现前端搜索联想功能,但是出于学习还是想了解一下实现此功能的原理性 回想起来 实现此功能很简单,1.前端输入字符串 文本改变 异步请求服务器 将返回的资料显示 ...
- 【Android自己定义View实战】之自己定义超简单SearchView搜索框
[Android自己定义View实战]之自己定义超简单SearchView搜索框 这篇文章是对之前文章的翻新,至于为什么我要又一次改动这篇文章?原因例如以下 1.有人举报我抄袭,原文链接:http:/ ...
- 基于PHP实现一个简单的在线聊天功能(轮询ajax )
基于PHP实现一个简单的在线聊天功能(轮询ajax ) 一.总结 1.用的轮询ajax 二.基于PHP实现一个简单的在线聊天功能 一直很想试着做一做这个有意思的功能,感觉复杂的不是数据交互和表结构,麻 ...
- (转)用C#实现实现简单的 Ping 的功能,用于测试网络是否已经连通
本文转载自:http://blog.csdn.net/xiamin/archive/2009/02/14/3889696.aspx 用C#实现实现简单的 Ping 的功能,用于测试网络是否已经联通 1 ...
- 简单实现UITableView索引功能(中英文首字母索引) (二) By HL
简单实现UITableView索引功能(中英文首字母索引)(一) ByH罗 相关类: NSString+PinYing(获取中英文首字母) 参考上面链接 #import "ViewCon ...
随机推荐
- Java中的equals和hashCode方法详解
Java中的equals和hashCode方法详解 转自 https://www.cnblogs.com/crazylqy/category/655181.html 参考:http://blog.c ...
- pandas 中有关isin()函数的介绍,python中del解释
- 【LeetCode刷题系列 - 003题】Longest Substring Without Repeating Characters
题目: Given a string, find the length of the longest substring without repeating characters. Example 1 ...
- python note 15 正则表达式
# 正则表达式 只和字符串打交道 # 正则表达式的规则# 规则 字符串 从字符串中找到符合规则的内容 # 字符组 : [] 写在中括号中的内容,都出现在下面的某一个字符的位置上都是符合规则的 # [0 ...
- find用法详解
一.find的用法 find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [express ...
- 转:Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-j8m0mf5q/mysqlclient
错误场景 第一次部署服务器时mysqlclient安装失败 思考 初步考虑是pip没有升级,最后发现不是这个原因. 解决办法 来源:https://blog.csdn.net/mr_tia/artic ...
- java8--List转为Map、分组、过滤、求和等操作----代码示例
Java 8 函数式编程风格 Java 迄今为止最令人激动的特征.这些新的语言特征允许采用函数式风格来进行编码,我们可以用这些特性完成许多有趣的功能.这些特性如此有趣以至于被认为是不合理的.他们说会影 ...
- 移动端h5调试方法
charles代理 使用技巧如下: http://www.jianshu.com/p/fdd7c681929c 1.手机wifi连接代理 以iphone为例,长按住wifi, 进入下一页,可看到 HT ...
- HDU 6041.I Curse Myself 无向仙人掌图
I Curse Myself Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- Asp.net Zero 应用实战-官方示例PhoneBook学习1
适用Zero版本:ASP.NET Core & Angular 2+ (aspnet-zero-core-3.1.0). 该版本官方有两个solution文件夹:Angular(前端) 和 a ...