首页 文章 精选 留言 我的

精选列表

搜索[python3],共1105篇文章
优秀的个人博客,低调大师

2018-05-14 代码考古-Python3官方教程字典例程

知乎原链 Data Structures中的第一个例程: >>> tel = {'jack': 4098, 'sape': 4139} >>> tel['guido'] = 4127 >>> tel {'sape': 4139, 'guido': 4127, 'jack': 4098} >>> tel['jack'] 4098 >>> del tel['sape'] >>> tel['irv'] = 4127 >>> tel {'guido': 4127, 'irv': 4127, 'jack': 4098} >>> list(tel.keys()) ['irv', 'guido', 'jack'] >>> sorted(tel.keys()) ['guido', 'irv', 'jack'] >>> 'guido' in tel True >>> 'jack' not in tel False 大多数读者也许都认为这些字符串和数字并没有特别意义. 如果真是这样, 这个例程还不如用 dict = {'aa': 100, 'bb': 200} 之类来的一目了然, 省去多余的猜度. 不巧发现"guido"是Python创作者的名字(Guido van Rossum), 就觉得不该这么简单. 根据python源码27年前的commit6fc178f46d40aa068a713b509904d343ee55cfa6, 这个教程中的示例代码是Guido本人编写的. 因此与他1991年8月附近的经历应该有关. 接着找到他的简历中的: From 1986 till 1991 I was with the Amoeba project, headed by Sape Mullender 发现Sape也是人名, 基本可以确定是他的同事的名字. 接下去搜到这里"Open Software Foundation"文末, Sape Mullender的电话是+20-592 4139, 可以印证例程中的变量tel应该指的是当时他们的电话号码后四位. 接着找到Jack的号码: +31 20 592 4098 另外还找到Guido用过4127这一号码, 也许这是CWI那时的一个多人号码, 如此文, 就能解释这个代码示例中还有"irv"也映射到了这个号码. 原来, 这是一个电话簿. 考虑到Python创造之初, 主要用户都是Guido的同事, 也是当时他写教程的读者, 这个示例代码对于他们来说是很容易理解的. 但随着几十年Python的推广, 它的含义也就被掩埋了. 英文代码风格中不提倡缩写名词挺合理的. 如果原例程中的变量名是phone或者telephone, 也会比tel好理解一些. 字符串的首字母大写也会更易于理解它们是人名. 汉化示例代码时, 打算就用"电话簿"作变量名.

优秀的个人博客,低调大师

Python3 与 NetCore 基础语法对比(List、Tuple、Dict、Set专栏)

Jupyter最新版:https://www.cnblogs.com/dotnetcrazy/p/9155310.html 在线演示:http://nbviewer.jupyter.org/github/lotapp/BaseCode/blob/master/python/notebook/1.POP/3.list_tuple_dict 更新:新增Python可变Tuple、List切片、Set的扩展:https://www.cnblogs.com/dotnetcrazy/p/9155310.html#extend 今天说说List和Tuple以及Dict。POP部分还有一些如Func、IO(也可以放OOP部分说)然后就说说面向对象吧。 先吐槽一下:Python面向对象真心需要规范,不然太容易走火入魔了 -_-!!! 汗,下次再说。。。 对比写作真的比单写累很多,希望大家多捧捧场 ^_^ 进入扩展:https://www.cnblogs.com/dotnetcrazy/p/9155310.html#ext 步入正题: 1.列表相关: Python定义一个列表(列表虽然可以存不同类型,一般我们把相同类型的值存列表里面,不同类型存字典里(key,value)) info_list=[] #空列表 infos_list=["C#","JavaScript"] 遍历和之前一样,for 或者 while 都可以(for扩展:https://www.cnblogs.com/dotnetcrazy/p/9102030.html#forelse) NetCore:var infos_list = new List<object>() { "C#", "JavaScript" }; 遍历可以用foreach,for,while Python列表的添加: # 末尾追加infos_list. append("Java") # 添加一个列表infos_list. extend(infos_list2) # 指定位置插入infos_list. insert(0,"Python") # 插入列表:infos_list .insert(0,temp_list) 看后面的 列表嵌套,是通过下标方式获取,eg: infos_list[0][1] Python在指定位置插入列表是真的插入一个列表进去,C#是把里面的元素挨个插入进去 NetCore:Add,AddRange,Insert,InsertRange (和Python插入列表有些区别) Python列表删除系列: infos_list. pop() #删除最后一个 infos_list. pop(0) #删除指定索引,不存在就报错 infos_list. remove("张三") # remove("")删除指定元素 ,不存在就报错 delinfos_list[1]#删除指定下标元素,不存在就报错 del infos_list#删除集合(集合再访问就不存在了)不同于C#给集合赋null 再过一遍 NetCore:移除指定索引:infos_list.RemoveAt(1); 移除指定值: infos_list.Remove(item);清空列表:infos_list.Clear(); Python修改:(只能通过索引修改) infos_list2[1]="PHP" #只有下标修改一种方式, 不存在则异常 # 想按值修改需要先查下标再修改 eg: infos_list2.index("张三") infos_list2[0]="GO" # infos_list2.index("dnt")# 不存在则异常 # 知识面拓展: https://www.zhihu.com/question/49098374 # 为什么python中不建议在for循环中修改列表? # 由于在遍历的过程中,删除了其中一个元素,导致后面的元素整体前移,导致有个元素成了漏网之鱼。 # 同样的,在遍历过程中,使用插入操作,也会导致类似的错误。这也就是问题里说的无法“跟踪”元素。 # 如果使用while,则可以在面对这样情况的时候灵活应对。 NetCore:基本上和Python一样 Python查询系列:in, not in, index, count if "张三" in names_list: names_list.remove("张三") if "大舅子" not in names_list: names_list.append("大舅子") names_list.index("王二麻子") names_list.count("逆天") NetCore:IndexOf , Count 查找用Contains,其他的先看看,后面会讲 Python排序 num_list. reverse() # 倒序 num_list. sort() # 从小到大排序 num_list. sort(reverse=True) # 从大到小 列表嵌套,获取用下标的方式:num_list[5][1] NetCore:var num_list2 = new List<object>() { 33, 44, 22,new List<object>(){11,55,77} }; 不能像python那样下标操作,可以定义多维数组来支持 num_list2[i][j] (PS,其实这个嵌套不太用,以后都是列表里面套Dict,类似与Json) 2.Tuple 元组 这次先说NetCore吧:(逆天ValueTuple用的比较多,下面案例就是用的这个) 元组系: https://msdn.microsoft.com/zh-cn/library/system.tuple.aspx 值元组: https://msdn.microsoft.com/zh-cn/library/system.valuetuple.aspx C#中元组主要是方便程序员,不用自然可以。比如:当你返回多个值是否还用ref out 或者返回一个list之类的?这些都需要先定义,比较麻烦.元祖在这些场景用的比较多。 先说说基本使用: 初始化: var test_tuple = ("萌萌哒", 1, 3, 5, "加息", "加息"); //这种方式就是valueTuple了(看vscode监视信息) 需要说下的是,取值只能通过 itemxxx来取了,然后就是 valueTuple的值是可以修改的 忽略上面说的(一般不会用的),直接进应用场景: 就说到这了,代码部分附录是有的 Python:用法基本上和列表差不多( 下标和前面说的用法一样,比如test_tuples[-1] 最后一个元素) 定义:一个元素: test_tuple1=(1,) test_tuple=("萌萌哒",1,3,5,"加息","加息") test_tuple.count("加息") test_tuple. index("萌萌哒") #没有find方法 test_tuple. index("加息", 1, 4) #从特定位置查找, 左闭右开区间==>[1,4) 来说说拆包相关的,C#的上面说了,这边来个案例即可: a=(1,2) b=a #把a的引用给b c,d=a #不是把a分别赋值给c和d, 等价于:c=a[0] d=a[1] 来个扩展吧(多维元组): some_tuples=[(2,"萌萌哒"),(4,3)] some_tuples[0] some_tuples[0][1] 3.Dict系列 Python遍历相关: #每一次相当于取一个元组,那可以用之前讲的例子来简化了:c,d=a #等价于:c=a[0] d=a[1] for k,v in infos_dict.items(): print("Key:%s,Value:%s"%(k,v)) NetCore:方式和Python差不多 foreach (KeyValuePair<string, object> kv in infos_dict) { Console.WriteLine($"Key:{kv.Key},Value:{kv.Value}"); } Python增删改系列: 增加、修改:infos_dict["wechat"]="dotnetcrazy" #有就修改,没就添加 删除系列: # 删除 del infos_dict["name"]#不存在就报错 #清空字典内容 infos_dict.clear() # 删除字典 del infos_dict NetCore: 添加:infos_dict.Add("wechat", "lll");infos_dict["wechat1"] = "lll"; 修改: infos_dict["wechat"] = "dotnetcrazy"; 删除: infos_dict.Remove("dog"); //不存在不报错 infos_dict.Clear(); //列表内容清空 Python查询系列:推荐:infos_dict.get("mmd")#查不到不会异常 NetCore:infos_dict["name"] 可以通过ContainsKey(key) 避免异常。看值就 ContainsValue(value) 扩展: 1.多维元组: some_tuples=[(2,"萌萌哒"),(4,3)] some_tuples[0] some_tuples[0][1] 2.运算符扩展:(+,*,in,not in) # 运算符扩展: test_str="www.baidu.com" test_list=[1,"d",5] test_dict={"name":"dnt","wechat":"xxx"} test_list1=[2,4,"n","t",3] # + 合并 (不支持字典) print(test_str+test_str) print(test_list+test_list1) # * 复制 (不支持字典) print(test_str*2) print(test_list*2) # in 是否存在(字典是查key) print("d" in test_str) #True print("d" in test_list) #True print("d" in test_dict) #False print("name" in test_dict) #True # not in 是否不存在(字典是查key) print("z" not in test_str) #True print("z" not in test_list) #True print("z" not in test_dict) #True print("name" not in test_dict) #False 3.内置函数扩展:(len,max,min,del) len(),这个就不说了,用的太多了 max(),求最大值,dict的最大值是比较的key 这个注意一种情况(当然了,你按照之前说的规范,list里面放同一种类型就不会出错了) min(),这个和max一样用 del() or del xxx删完就木有了 #可以先忽略cmp(item1, item2)比较两个值 #是Python2里面有的 cmp(1,2) ==> -1 #cmp在比较字典数据时,先比较键,再比较值 知识扩展: 可变的元组(元组在定义的时候就不能变了,但是可以通过类似这种方式来改变) List切片: Set集合扩展: 更新:(漏了一个删除的方法): 概念再补充下: # dict内部存放的顺序和key放入的顺序是没有关系的# dict的key必须是不可变对象(dict根据key进行hash算法,来计算value的存储位置# 如果每次计算相同的key得出的结果不同,那dict内部就完全混乱了) 用一张图理解一下:(测试结果:元组是可以作为Key的 -_-!) 附录Code: Python:https://github.com/lotapp/BaseCode/tree/master/python/1.POP/3.list_tuple_dict Python List: # 定义一个列表,列表虽然可以存不同类型,一般我们把相同类型的值存列表里面,不同类型存字典里(key,value) infos_list=["C#","JavaScript"]#[] # ########################################################### # # 遍历 for while # for item in infos_list: # print(item) # i=0 # while i<len(infos_list): # print(infos_list[i]) # i+=1 # ########################################################### # # 增加 # # 末尾追加 # infos_list.append("Java") # print(infos_list) # # 指定位置插入 # infos_list.insert(0,"Python") # print(infos_list) # temp_list=["test1","test2"] # infos_list.insert(0,temp_list) # print(infos_list) # # 添加一个列表 # infos_list2=["张三",21]#python里面的列表类似于List<object> # infos_list.extend(infos_list2) # print(infos_list) # # help(infos_list.extend)#可以查看etend方法描述 # ########################################################### # # 删除 # # pop()删除最后一个元素,返回删掉的元素 # # pop(index) 删除指定下标元素 # print(infos_list.pop()) # print(infos_list) # print(infos_list.pop(0)) # # print(infos_list.pop(10)) #不存在就报错 # print(infos_list) # # remove("")删除指定元素 # infos_list.remove("张三") # # infos_list.remove("dnt") #不存在就报错 # print(infos_list) # # del xxx[index] 删除指定下标元素 # del infos_list[1] # print(infos_list) # # del infos_list[10] #不存在就报错 # # del infos_list #删除集合(集合再访问就不存在了) # ########################################################### # # 修改 xxx[index]=xx # # 注意:一般不推荐在for循环里面修改 # print(infos_list2) # infos_list2[1]="PHP" #只有下标修改一种方式 # # infos_list2[3]="GO" #不存在则异常 # print(infos_list2) # # 想按值修改需要先查下标再修改 # infos_list2.index("张三") # infos_list2[0]="GO" # print(infos_list2) # # infos_list2.index("dnt")#不存在则异常 # # 知识面拓展: https://www.zhihu.com/question/49098374 # # 为什么python中不建议在for循环中修改列表? # # 由于在遍历的过程中,删除了其中一个元素,导致后面的元素整体前移,导致有个元素成了漏网之鱼。 # # 同样的,在遍历过程中,使用插入操作,也会导致类似的错误。这也就是问题里说的无法“跟踪”元素。 # # 如果使用while,则可以在面对这样情况的时候灵活应对。 ########################################################### # # 查询 in, not in, index, count # # # for扩展:https://www.cnblogs.com/dotnetcrazy/p/9102030.html#forelse # names_list=["张三","李四","王二麻子"] # # #张三在列表中执行操作 # if "张三" in names_list: # names_list.remove("张三") # print(names_list) # # #查看"大舅子"不在列表中执行操作 # if "大舅子" not in names_list: # names_list.append("大舅子") # print(names_list) # # #查询王二麻子的索引 # print(names_list.index("王二麻子")) # print(names_list.count("大舅子")) # print(names_list.count("逆天")) ########################################################### # # 排序(sort, reverse 逆置) # num_list=[1,3,5,88,7] # #倒序 # num_list.reverse() # print(num_list) # # 从小到大排序 # num_list.sort() # print(num_list) # # 从大到小 # num_list.sort(reverse=True) # print(num_list) # # ########################################################### # # #列表嵌套(列表也是可以嵌套的) # num_list2=[33,44,22] # num_list.append(num_list2) # print(num_list) # # for item in num_list: # # print(item,end="") # print(num_list[5]) # print(num_list[5][1]) # # ########################################################### # # # 引入Null==>None # # a=[1,2,3,4] # # b=[5,6] # # a=a.append(b)#a.append(b)没有返回值 # # print(a)#None View Code Python Tuple: # 只能查询,其他操作和列表差不多(不可变) test_tuple=("萌萌哒",1,3,5,"加息","加息") # count index print(test_tuple.count("加息")) print(test_tuple.index("萌萌哒"))#没有find方法 # 注意是左闭右开区间==>[1,4) # print(test_tuple.index("加息", 1, 4))#查不到报错:ValueError: tuple.index(x): x not in tuple #下标取 print(test_tuple[0]) # 遍历 for item in test_tuple: print(item) i=0 while i<len(test_tuple): print(test_tuple[i]) i+=1 # 扩展: test_tuple1=(1,) #(1)就不是元祖了 test_tuple2=(2) print(type(test_tuple1)) print(type(test_tuple2)) # # ============================================== # 扩展:(后面讲字典遍历的时候会再提一下的) a=(1,2) b=a#把a的引用给b #a里面两个值,直接给左边两个变量赋值了(有点像拆包了) c,d=a #不是把a分别赋值给c和d,等价于:c=a[0] d=a[1] print(a) print(b) print(c) print(d) View Code Python Dict: infos_dict={"name":"dnt","web":"dkill.net"} # # 遍历 # for item in infos_dict.keys(): # print(item) # #注意,如果你直接对infos遍历,其实只是遍历keys # for item in infos_dict: # print(item) # for item in infos_dict.values(): # print(item) # for item in infos_dict.items(): # print("Key:%s,Value:%s"%(item[0],item[1])) # #每一次相当于取一个元组,那可以用之前讲的例子来简化了:c,d=a #等价于:c=a[0] d=a[1] # for k,v in infos_dict.items(): # print("Key:%s,Value:%s"%(k,v)) # # 增加 修改 (有就修改,没就添加) # # 添加 # infos_dict["wechat"]="lll" # print(infos_dict) # # 修改 # infos_dict["wechat"]="dotnetcrazy" # print(infos_dict) # # 删除 # del infos_dict["name"] # del infos_dict["dog"] #不存在就报错 # print(infos_dict) # #清空字典内容 # infos_dict.clear() # print(infos_dict) # # 删除字典 # del infos_dict # 查询 infos_dict["name"] # infos_dict["mmd"] #查不到就异常 infos_dict.get("name") infos_dict.get("mmd")#查不到不会异常 # 查看帮助 # help(infos_dict) len(infos_dict) #有几对key,value # infos_dict.has_key("name") #这个是python2里面的 View Code NetCore:https://github.com/lotapp/BaseCode/tree/master/netcore/1_POP NetCore List: // using System; // using System.Collections.Generic; // using System.Linq; // namespace aibaseConsole // { // public static class Program // { // private static void Main() // { // #region List // //# 定义一个列表 // // # infos_list=["C#","JavaScript"]#[] // var infos_list = new List<object>() { "C#", "JavaScript" }; // // var infos_list2 = new List<object>() { "张三", 21 }; // // // # ########################################################### // // // # # 遍历 for while // // // # for item in infos_list: // // // # print(item) // // foreach (var item in infos_list) // // { // // System.Console.WriteLine(item); // // } // // for (int i = 0; i < infos_list.Count; i++) // // { // // System.Console.WriteLine(infos_list[i]); // // } // // // # i=0 // // // # while i<len(infos_list): // // // # print(infos_list[i]) // // // # i+=1 // // int j=0; // // while(j<infos_list.Count){ // // Console.WriteLine(infos_list[j++]); // // } // // // # ########################################################### // // // # # 增加 // // // # # 末尾追加 // // // # infos_list.append("Java") // // // # print(infos_list) // // DivPrintList(infos_list); // // infos_list.Add("Java"); // // DivPrintList(infos_list); // // // # # 指定位置插入 // // // # infos_list.insert(0,"Python") // // // # print(infos_list) // // infos_list.Insert(0,"Python"); // // DivPrintList(infos_list); // // // # # 添加一个列表 // // // # infos_list2=["张三",21]#python里面的列表类似于List<object> // // // # infos_list.extend(infos_list2) // // // # print(infos_list) // // infos_list.AddRange(infos_list2); // // DivPrintList(infos_list); // // /*C#有insertRange方法 */ // // DivPrintList(infos_list2,"List2原来的列表:"); // // infos_list2.InsertRange(0,infos_list); // // DivPrintList(infos_list2,"List2变化后列表:"); // // // # # help(infos_list.extend)#可以查看etend方法描述 // // // # ########################################################### // // // # # 删除 // // // # # pop()删除最后一个元素,返回删掉的元素 // // // # # pop(index) 删除指定下标元素 // // // # print(infos_list.pop()) // // // # print(infos_list) // // // # print(infos_list.pop(1)) // // // # # print(infos_list.pop(10)) #不存在就报错 // // // # print(infos_list) // // // # # remove("")删除指定元素 // // // # infos_list.remove("张三") // // // # # infos_list.remove("dnt") #不存在就报错 // // // # print(infos_list) // // // # # del xxx[index] 删除指定下标元素 // // // # del infos_list[1] // // // # print(infos_list) // // // # # del infos_list[10] #不存在就报错 // // // # del infos_list #删除集合(集合再访问就不存在了) // // DivPrintList(infos_list); // // infos_list.RemoveAt(1); // // // infos_list.RemoveAt(10);//不存在则报错 // // // infos_list.RemoveRange(0,1); //可以移除多个 // // DivPrintList(infos_list); // // infos_list.Remove("我家在东北吗?"); //移除指定item,不存在不会报错 // // DivPrintList(infos_list,"清空前:"); // // infos_list.Clear();//清空列表 // // DivPrintList(infos_list,"清空后:"); // // // # ########################################################### // // // # # 修改 xxx[index]=xx // // // # # 注意:一般不推荐在for循环里面修改 // // // # print(infos_list2) // // // # infos_list2[1]="PHP" #只有下标修改一种方式 // // // # # infos_list2[3]="GO" #不存在则异常 // // // # print(infos_list2) // // DivPrintList(infos_list2); // // infos_list2[1] = "PHP"; // // // infos_list2[3]="GO"; //不存在则异常 // // DivPrintList(infos_list2); // // // # # 想按值修改需要先查下标再修改 // // // # infos_list2.index("张三") // // // # infos_list2[0]="GO" // // // # print(infos_list2) // // // # # infos_list2.index("dnt")#不存在则异常 // // int index = infos_list2.IndexOf("张三"); // // infos_list2[index] = "GO"; // // DivPrintList(infos_list2); // // infos_list2.IndexOf("dnt");//不存在返回-1 // // // ########################################################### // // // # 查询 in, not in, index, count // // // # # for扩展:https://www.cnblogs.com/dotnetcrazy/p/9102030.html#forelse // // // # names_list=["张三","李四","王二麻子"] // // var names_list=new List<string>(){"张三","李四","王二麻子"}; // // // Console.WriteLine(names_list.Find(i=>i=="张三")); // // // Console.WriteLine(names_list.FirstOrDefault(i=>i=="张三")); // // Console.WriteLine(names_list.Exists(i=>i=="张三")); // // System.Console.WriteLine(names_list.Contains("张三")); // // // # #张三在列表中执行操作 // // // # if "张三" in names_list: // // // # names_list.remove("张三") // // // # else: // // // # print(names_list) // // // # #查看"大舅子"不在列表中执行操作 // // // # if "大舅子" not in names_list: // // // # names_list.append("大舅子") // // // # else: // // // # print(names_list) // // // # #查询王二麻子的索引 // // // # print(names_list.index("王二麻子")) // // // names_list.IndexOf("王二麻子"); // // // # print(names_list.count("大舅子")) // // // # print(names_list.count("逆天")) // // // Console.WriteLine(names_list.Count); // // // ########################################################### // // // # # 排序(sort, reverse 逆置) // // // # num_list=[1,3,5,88,7] // // var num_list = new List<object>() { 1, 3, 5, 88, 7 }; // // // # #倒序 // // // # num_list.reverse() // // // # print(num_list) // // num_list.Reverse(); // // DivPrintList(num_list); // // // # # 从小到大排序 // // // # num_list.sort() // // // # print(num_list) // // num_list.Sort(); // // DivPrintList(num_list); // // // # # 从大到小 // // // # num_list.sort(reverse=True) // // // # print(num_list) // // num_list.Sort(); // // num_list.Reverse(); // // DivPrintList(num_list); // // // # ########################################################### // // // # #列表嵌套(列表也是可以嵌套的) // // // # num_list2=[33,44,22] // // // # num_list.append(num_list2) // // // # print(num_list) // // var num_list2 = new List<object>() { 33, 44, 22,new List<object>(){11,55,77} }; // // DivPrintList(num_list2);//可以定义多维数组来支持 num_list2[i][j] // // // # for item in num_list: // // // # print(item) // // // # ########################################################### // // // # # 引入Null==>None // // // # a=[1,2,3,4] // // // # b=[5,6] // // // # a=a.append(b)#a.append(b)没有返回值 // // // # print(a)#None // #endregion // // Console.Read(); // } // private static void DivPrintList(List<object> list, string say = "") // { // Console.WriteLine($"\n{say}"); // foreach (var item in list) // { // System.Console.Write($"{item} "); // } // } // } // } View Code NetCore Tuple: // using System; // namespace aibaseConsole // { // public static class Program // { // private static void Main() // { // #region Tuple // // C#中元组主要是方便程序员,不用自然可以. // // 元祖系:https://msdn.microsoft.com/zh-cn/library/system.tuple.aspx // // 值元组:https://msdn.microsoft.com/zh-cn/library/system.valuetuple.aspx // // 比如:当你返回多个值是否还用ref out 或者返回一个list之类的? // // 这些都需要先定义,比较麻烦.元祖在一些场景用的比较多 eg: // // 初始化 // // var test_tuple = ("萌萌哒", 1, 3, 5, "加息", "加息"); //这种方式就是valueTuple了 // // test_tuple.Item1 = "ddd";//可以修改值 // // test_tuple.GetType(); // // test_tuple.itemxxx //获取值只能通过itemxxx // var result = GetCityAndTel(); //支持async/await模式 // var city = result.city; // var tel = result.tel; // // 拆包方式: // var (city1, tel1) = GetCityAndTel(); // #endregion // // Console.Read(); // } // // public static (string city, string tel) GetCityAndTel() // // { // // return ("北京", "110"); // // } // // 简化写法 // public static (string city, string tel) GetCityAndTel() => ("北京", "110"); // } // } View Code NetCore Dict: using System; using System.Collections.Generic; namespace aibaseConsole { public static class Program { private static void Main() { #region Dict // infos_dict={"name":"dnt","web":"dkill.net"} // # # 遍历 // # for item in infos_dict.keys(): // # print(item) // # for item in infos_dict.values(): // # print(item) // # for item in infos_dict.items(): // # print("Key:%s,Value:%s"%(item[0],item[1])) // # #每一次相当于取一个元组,那可以用之前讲的例子来简化了:c,d=a #等价于:c=a[0] d=a[1] // # for k,v in infos_dict.items(): // # print("Key:%s,Value:%s"%(k,v)) var infos_dict = new Dictionary<string, object>{ {"name","dnt"}, {"web","dkill.net"} }; // foreach (var item in infos_dict.Keys) // { // System.Console.WriteLine(item); // } // foreach (var item in infos_dict.Values) // { // System.Console.WriteLine(item); // } // foreach (KeyValuePair<string, object> kv in infos_dict) // { // // System.Console.WriteLine("Key:%s,Value:%s",(kv.Key,kv.Value)); // System.Console.WriteLine($"Key:{kv.Key},Value:{kv.Value}"); // } // // # # 增加 修改 (有就修改,没就添加) // // # # 添加 // // # infos_dict["wechat"]="lll" // // # print(infos_dict) // infos_dict.Add("wechat", "lll"); // infos_dict["wechat1"] = "lll"; // // # # 修改 // // # infos_dict["wechat"]="dotnetcrazy" // // # print(infos_dict) // infos_dict["wechat"] = "dotnetcrazy"; // // # # 删除 // // # del infos_dict["name"] // // # del infos_dict["dog"] #不存在就报错 // // # print(infos_dict) // infos_dict.Remove("name"); // infos_dict.Remove("dog"); // // # #清空列表内容 // // # infos_dict.clear() // // # print(infos_dict) // infos_dict.Clear(); // // # # 删除列表 // // # del infos_dict // # 查询 // infos_dict["name"] // infos_dict["mmd"] #查不到就异常 // infos_dict.get("name") // infos_dict.get("mmd")#查不到不会异常 Console.WriteLine(infos_dict["name"]); // Console.WriteLine(infos_dict["mmd"]); //#查不到就异常 // 先看看有没有 ContainsKey(key),看值就 ContainsValue(value) if (infos_dict.ContainsKey("mmd")) Console.WriteLine(infos_dict["mmd"]); // # 查看帮助 // help(infos_dict) // len(infos_dict) #有几对key,value Console.WriteLine(infos_dict.Count); #endregion // Console.Read(); } } } View Code 作者: 毒逆天 出处: https://www.cnblogs.com/dotnetcrazy 打赏: 18i4JpL6g54yAPAefdtgqwRrZ43YJwAV5z 本文版权归作者和博客园共有。欢迎转载,但必须保留此段声明,且在文章页面明显位置给出原文连接!

优秀的个人博客,低调大师

利用python3获取当前计算机的名字和IP

众所周知,python是一门非常强大且简洁的语言。本篇主要来为大家介绍windows和linux下如何利用python获取当前计算机的ip和计算机名。 windows下,主要是利用socket模块。具体代码如下: import socket 获取 import socket Compute_name=socket.getfqdn(socket.gethostname()) # get name Compute_addr=socket.gethostbyname(Compute_name) #get ip print(Compute_name) print(Compute_addr) 运行结果 但是值得注意的是这里获取的ip地址是内网ip地址。 ———————————————— 获取本机的mac地址 1 2 3 4 import uuid def get_mac_address(): mac = uuid.UUID( int = uuid.getnode()). hex [ - 12 :] return ":" .join([mac[e:e + 2 ] for e in range ( 0 , 11 , 2 )]) —————————————————————————— Linux下获取IP地址,本机名 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import socket import fcntl import struct def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) >>> get_ip_address('lo') '127.0.0.1' >>> get_ip_address('eth0') '38.113.228.130'

优秀的个人博客,低调大师

阿里云函数计算带Http触发器模板(使用Python3

目前阿里云函数计算支持Http触发器,由于Http触发器使用得比较多,特意制作一个模板,可以直接下载该模板使用。另外,模板自带VScode调试功能,方便调试。 项目地址 安装模板 安装nodejs 安装docker和fun,官方参考教程:安装教程 初始化模板 fun init -n fun-test-http https://github.com/l616769490/python3-http-example.git 可以将【fun-test-http】替换成你自己的文件夹名 使用模板 使用vscode打开模板文件夹 打开终端,运行调试命令:fun local start -d 8888 -c vscode,控制台会自动输出调试链接 按住ctrl并单击链接,在浏览器中打开调试链接 调试程序 调试完成后可以在浏览器中看到返回结果 参考资料 阿里云官方示例

优秀的个人博客,低调大师

Python3中如何做的自定义模块的引用?

前言python引用与java很大区别 java中,比如jar包com.my.test 中有一个Employee类,则可以 import com.my.test; 使用: Employee employee=new Employee() python 中,Employee.py文件有一个class Employee 则引用 from com.my.test import Employee 使用:employee=Employee() 发现报错 必须:employee=Employee.Employee()才正确 注意:.java文件中必须有一个类与文件名名字一样;但是python中可以不一样,python中py文件是模块 from com.my.test import Employee import只是指向模块,并不是指向类。如果Employee.py文件中有一个 Work类,就更明白了。 如果直接使用Word类,可以如下调用 from com.my.test.Employee import * from com.my.test.Employee import Work w=Work() 如果Employee 里面有不包含在类类的方法,比如count方法,则需要 from com.my.test impot Employee c= Employee.count() 小编推荐一个学python的学习qun 740322234无论你是大牛还是小白,是想转行还是想入行都可以来了解一起进步一起学习!裙内有开发工具,很多干货和技术资料分享!

优秀的个人博客,低调大师

Agileutil v0.0.14 发布,超简单、易用的轻量级 Python3 RPC 框架

本次更新的版本是v0.0.14, 支持通过@rpc装饰器修饰一个类。 下面是一个TCP协议的服务端例子。 创建一个TcpRpcServer对象, 指定服务端监听地址和端口 通过@rpc装饰器注册需要被客户端请求的方法 调用serve()方法,开始处理客户端请求 from agileutil.rpc.server import TcpRpcServer, rpc @rpc class TestService: def hello(self, name): return "Hello, {}!".format(name) def add(self, a, b, c): return a + b + c @rpc def hello(name): return "Hello, {}!".format(name) server = TcpRpcServer('0.0.0.0', 9988) server.serve() TCP RPC 客户端 创建TcpRpcClient对象,指定RPC服务端地址 通过call()方法,指定服务端方法名称和参数(注意:如果方法名不存在,或者服务端未调用@rpc装饰器注册,那么call()方法将抛出异常) call() 方法的返回值和在本地调用一样,原来是什么返回类型,就还是什么(例如返回字典、列表、对象甚至内置类型,经过序列化后,不会发生改变) from agileutil.rpc.client import TcpRpcClient cli = TcpRpcClient('127.0.0.1', 9988, timeout = 2) resp = cli.call('TestService.hello', args=('xiaoming',)) print(resp) resp = cli.call('TestService.add', args=(1, 2, 3)) print(resp) resp = cli.call('hello', args=('xiaoming',)) print(resp)

优秀的个人博客,低调大师

Python3数据分析——(1)NumPy快速入门教程(官网教程翻译)

Numpy(Numerical Python) Numpy: 提供了一个在Python中做科学计算的基础库,重在数值计算,主要用于多维数组(矩阵)处理的库;用来存储和处理大型矩阵,比Python自身的嵌套列表结构要高效的多。本身是由C语言开发,是个很基础的扩展;Python其余的科学计算扩展大部分都是以此为基础。 1.高性能科学计算和数据分析的基础包 2.ndarray,多维数组(矩阵),具有矢量运算能力,快速、节省空间 3.矩阵运算,无需循环,可完成类似Matlab中的矢量运算 4.线性代数、随机数生成 5.import numpy as np 先决条件 在阅读这个教程之前,你多少需要知道点Python。如果你想从新回忆下,请看看Python Tutorial. 在阅读本教程之前,您应该了解一些Python。如果你想刷新你的记忆,请看看Python教程 基础篇 NumPy的主要对象是同种元素的多维数组。这是一个所有的元素都是一种类型、通过一个正整数元组索引的元素表格(通常是元素是数字)。在NumPy中维度(dimensions)叫做轴(axes),轴的个数叫做秩(rank)。 例如,在3D空间一个点的坐标[1, 2, 3]是一个秩为1的数组,因为它只有一个轴。那个轴长度为3.又例如,在以下例子中,数组的秩为2(它有两个维度).第一个维度长度为2,第二个维度长度为3. [[ 1., 0., 0.], [ 0., 1., 2.]] NumPy的数组类被称作ndarray。通常被称作数组。注意numpy.array和标准Python库类array.array并不相同,后者只处理一维数组和提供少量功能。更多重要ndarray对象属性有: ndarray.ndim 数组轴的个数,在python的世界中,轴的个数被称作秩 ndarray.shape 数组的维度。这是一个指示数组在每个维度上大小的整数元组。例如一个n排m列的矩阵,它的shape属性将是(2,3),这个元组的长度显然是秩,即维度或者ndim属性 ndarray.size 数组元素的总个数,等于shape属性中元组元素的乘积。 ndarray.dtype 一个用来描述数组中元素类型的对象,可以通过创造或指定dtype使用标准Python类型。另外NumPy提供它自己的数据类型。 ndarray.itemsize 数组中每个元素的字节大小。例如,一个元素类型为float64的数组itemsiz属性值为8(=64/8),又如,一个元素类型为complex32的数组itemsize属性为4(=32/8). ndarray.data 包含实际数组元素的缓冲区,通常我们不需要使用这个属性,因为我们总是通过索引来使用数组中的元素。 一个例子 >>> import numpy as np >>> a = np.arange(15).reshape(3, 5) >>> a array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]) >>> a.shape (3, 5) >>> a.ndim 2 >>> a.dtype.name 'int64' >>> a.itemsize 8 >>> a.size 15 >>> type(a) <type 'numpy.ndarray'> >>> b = np.array([6, 7, 8]) >>> b array([6, 7, 8]) >>> type(b) <type 'numpy.ndarray'> 创建数组 有好几种创建数组的方法。 例如,你可以使用array函数从常规的Python列表和元组创造数组。所创建的数组类型由原序列中的元素类型推导而来。 >>> import numpy as np >>> a = np.array( [2,3,4] ) >>> a array([2, 3, 4]) >>> a.dtypedtype('int32') >>> b = np.array([1.2, 3.5, 5.1]) >>> b.dtype dtype('float64') 一个常见的错误包括用多个数值参数调用`array`而不是提供一个由数值组成的列表作为一个参数。 >>> a = np.array(1,2,3,4) # WRONG >>> a = np.array([1,2,3,4]) # RIGHT 数组将序列包含序列转化成二维的数组,序列包含序列包含序列转化成三维数组等等。 >>> b = np.array( [ (1.5,2,3), (4,5,6) ] ) >>> b array([[ 1.5, 2. , 3. ], [ 4. , 5. , 6. ]]) 数组类型可以在创建时显示指定 >>> c = np.array( [ [1,2], [3,4] ], np.dtype=complex ) >>> c array([[ 1.+0.j, 2.+0.j], [ 3.+0.j, 4.+0.j]]) 通常,数组的元素开始都是未知的,但是它的大小已知。因此,NumPy提供了一些使用占位符创建数组的函数。这最小化了扩展数组的需要和高昂的运算代价。 函数zeros创建一个全是0的数组,函数ones创建一个全1的数组,函数empty创建一个内容随机并且依赖与内存状态的数组。默认创建的数组类型(dtype)都是float64。 >>> np.zeros( (3,4) ) array([[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]]) >>> np.ones( (2,3,4), np.dtype=int16 ) # dtype can also be specified array([[[ 1, 1, 1, 1], [ 1, 1, 1, 1], [ 1, 1, 1, 1]], [[ 1, 1, 1, 1], [ 1, 1, 1, 1], [ 1, 1, 1, 1]]], np.dtype=int16) >>> np.empty( (2,3) ) array([[ 3.73603959e-262, 6.02658058e-154, 6.55490914e-260], [ 5.30498948e-313, 3.14673309e-307, 1.00000000e+000]]) 为了创建一个数列,NumPy提供一个类似arange的函数返回数组而不是列表: >>> np.arange( 10, 30, 5 ) array([10, 15, 20, 25]) >>> np.arange( 0, 2, 0.3 ) # it accepts float arguments array([ 0. , 0.3, 0.6, 0.9, 1.2, 1.5, 1.8]) 当arange使用浮点数参数时,由于有限的浮点数精度,通常无法预测获得的元素个数。因此,最好使用函数linspace去接收我们想要的元素个数来代替用range来指定步长。 其它函数array, zeros, zeros_like, ones, ones_like, empty, empty_like, arange, linspace, rand, randn, fromfunction, fromfile参考:NumPy示例 打印数组 当你打印一个数组,NumPy以类似嵌套列表的形式显示它,但是呈以下布局: 最后的轴从左到右打印 次后的轴从顶向下打印 剩下的轴从顶向下打印,每个切片通过一个空行与下一个隔开 一维数组被打印成行,二维数组成矩阵,三维数组成矩阵列表。 >>> a = np.arange(6) # 1d array >>> print(a) [0 1 2 3 4 5] >>> >>> b =np.arange(12).reshape(4,3) # 2d array >>> print(b) [[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11]] >>> >>> c = np.arange(24).reshape(2,3,4) # 3d array >>> print(c) [[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16 17 18 19] [20 21 22 23]]] 查看形状操作一节获得有关reshape的更多细节 如果一个数组用来打印太大了,NumPy自动省略中间部分而只打印角落 >>> print(np.arange(10000)) [ 0 1 2 ..., 9997 9998 9999] >>> >>> print(np.arange(10000).reshape(100,100)) [[ 0 1 2 ..., 97 98 99] [ 100 101 102 ..., 197 198 199] [ 200 201 202 ..., 297 298 299] ..., [9700 9701 9702 ..., 9797 9798 9799] [9800 9801 9802 ..., 9897 9898 9899] [9900 9901 9902 ..., 9997 9998 9999]] 禁用NumPy的这种行为并强制打印整个数组,你可以设置printoptions参数来更改打印选项。 >>> set_printoptions(threshold='nan') 基本运算 数组的算术运算是按元素的。新的数组被创建并且被结果填充。 >>> a = np.array( [20,30,40,50] ) >>> b = np.arange( 4 ) >>> b array([0, 1, 2, 3]) >>> c = a-b >>> c array([20, 29, 38, 47]) >>> b**2 array([0, 1, 4, 9]) >>> 10*np.sin(a) array([ 9.12945251, -9.88031624, 7.4511316 , -2.62374854]) >>> a<35 array([True, True, False, False], dtype=bool) 不像许多矩阵语言,NumPy中的乘法运算符*指示按元素计算,矩阵乘法可以使用dot函数或创建矩阵对象实现(参见教程中的矩阵章节) >>> A = np.array( [[1,1], ... [0,1]] ) >>> B = np.array( [[2,0], ... [3,4]] ) >>> A*B # elementwise product array([[2, 0], [0, 4]]) >>> np.dot(A,B) # matrix product >>>A.dot(B) #another matrix product array([[5, 4], [3, 4]]) 有些操作符像+=和*=被用来更改已存在数组而不创建一个新的数组。 >>> a = np.ones((2,3), dtype=int) >>> b = np.random.random((2,3)) >>> a *= 3 >>> a array([[3, 3, 3], [3, 3, 3]]) >>> b += a >>> b array([[ 3.69092703, 3.8324276 , 3.0114541 ], [ 3.18679111, 3.3039349 , 3.37600289]]) >>> a += b # b is notautomatically converted to integer type TypeError: Cannot cast ufunc add output from dtype('float64') to dtype('int64') with casting rule 'same_kind' 当运算的是不同类型的数组时,结果数组和更普遍和精确的已知(这种行为叫做upcast)。 >>> a = np.ones(3, dtype=np.int32) >>> b = np.linspace(0,pi,3) >>> b.dtype.name 'float64' >>> c = a+b >>> c array([ 1. , 2.57079633, 4.14159265]) >>> c.dtype.name 'float64' >>> d = np.exp(c*1j) >>> d array([ 0.54030231+0.84147098j, -0.84147098+0.54030231j, -0.54030231-0.84147098j]) >>> d.dtype.name 'complex128' 许多非数组运算,如计算数组所有元素之和,被作为ndarray类的方法实现 >>> a = np.random.random((2,3)) >>> a array([[ 0.6903007 , 0.39168346, 0.16524769], [ 0.48819875, 0.77188505, 0.94792155]]) >>> a.sum() 3.4552372100521485 >>> a.min() 0.16524768654743593 >>> a.max() 0.9479215542670073 这些运算默认应用到数组好像它就是一个数字组成的列表,无关数组的形状。然而,指定axis参数你可以吧运算应用到数组指定的轴上: >>> b = np.arange(12).reshape(3,4) >>> b array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> >>> b.sum(axis=0) # sum of each column array([12, 15, 18, 21]) >>> >>> b.min(axis=1) # min of each row array([0, 4, 8]) >>> >>> b.cumsum(axis=1) # cumulative sum along each row array([[ 0, 1, 3, 6], [ 4, 9, 15, 22], [ 8, 17, 27, 38]]) 通用函数(ufunc) NumPy提供常见的数学函数如sin,cos和exp。在NumPy中,这些叫作“通用函数”(ufunc)。在NumPy里这些函数作用按数组的元素运算,产生一个数组作为输出。 >>> B = np.arange(3) >>> B array([0, 1, 2]) >>> np.exp(B) array([ 1. , 2.71828183, 7.3890561 ]) >>> np.sqrt(B) array([ 0. , 1. , 1.41421356]) >>> C = np.array([2., -1., 4.]) >>> np.add(B, C) array([ 2., 0., 6.]) 更多函数all, alltrue, any, apply along axis, argmax, argmin, argsort, average, bincount, ceil, clip, conj, conjugate, corrcoef, cov, cross, cumprod, cumsum, diff, dot, floor, inner, inv, lexsort, max, maximum, mean, median, min, minimum, nonzero, outer, prod, re, round, sometrue, sort, std, sum, trace, transpose, var, vdot, vectorize, where 参见:NumPy示例 索引,切片和迭代 一维数组可以被索引、切片和迭代,就像列表和其它Python序列。 >>> a = np.arange(10)**3 >>> a array([ 0, 1, 8, 27, 64, 125, 216, 343, 512, 729]) >>> a[2] 8 >>> a[2:5] array([ 8, 27, 64]) >>> a[:6:2] = -1000 # equivalent to a[0:6:2] = -1000; from start to position 6, exclusive, set every 2nd element to -1000 >>> a array([-1000, 1, -1000, 27, -1000, 125, 216, 343, 512, 729]) >>> a[ : :-1] # reversed a array([ 729, 512, 343, 216, 125, -1000, 27, -1000, 1, -1000]) >>> for i in a: ... print(i**(1/3.)), ... nan 1.0 nan 3.0 nan 5.0 6.0 7.0 8.0 9.0 多维数组可以每个轴有一个索引。这些索引由一个逗号分割的元组给出。 >>> def f(x,y): ... return 10*x+y ... >>> b = np.fromfunction(f,(5,4),dtype=int) >>> b array([[ 0, 1, 2, 3], [10, 11, 12, 13], [20, 21, 22, 23], [30, 31, 32, 33], [40, 41, 42, 43]]) >>> b[2,3] 23 >>> b[0:5, 1] # each row in the second column of b array([ 1, 11, 21, 31, 41]) >>> b[ : ,1] # equivalent to the previous example array([ 1, 11, 21, 31, 41]) >>> b[1:3, : ] # each column in the second and third row of b array([[10, 11, 12, 13], [20, 21, 22, 23]]) 当少于轴数的索引被提供时,确失的索引被认为是整个切片: >>> b[-1] # the last row. Equivalent to b[-1,:] array([40, 41, 42, 43]) b[i]中括号中的表达式被当作i和一系列:,来代表剩下的轴。NumPy也允许你使用“点”像b[i,...]。 点(…)代表许多产生一个完整的索引元组必要的分号。如果x是秩为5的数组(即它有5个轴),那么: x[1,2,…] 等同于 x[1,2,:,:,:], x[…,3] 等同于 x[:,:,:,:,3] x[4,…,5,:] 等同 x[4,:,:,5,:]. >>> c = np.array( [ [[ 0, 1, 2], # a 3D array (two stacked 2D arrays) ... [ 10, 12, 13]], ... [[100,101,102], ... [110,112,113]]]) >>> c.shape (2, 2, 3) >>> c[1,...] # same as c[1,:,:] or c[1] array([[100, 101, 102], [110, 112, 113]]) >>> c[...,2] # same as c[:,:,2] array([[ 2, 13], [102, 113]]) 迭代多维数组是就第一个轴而言的: >>> for row in b: ... print(row) ... [0 1 2 3] [10 11 12 13] [20 21 22 23] [30 31 32 33] [40 41 42 43] 然而,如果一个人想对每个数组中元素进行运算,我们可以使用flat属性,该属性是数组元素的一个迭代器: >>> for element in b.flat: ... print(element), ... 0 1 2 3 10 11 12 13 20 21 22 23 30 31 32 33 40 41 42 43 更多[], …, newaxis, ndenumerate, indices, index exp 参考NumPy示例 形状操作 更改数组的形状 一个数组的形状由它每个轴上的元素个数给出: >>> a = np.floor(10*np.random.random((3,4))) >>> a array([[ 2., 8., 0., 6.], [ 4., 5., 1., 1.], [ 8., 9., 3., 6.]]) >>> a.shape (3, 4) 一个数组的形状可以被多种命令修改: >>> a.ravel() # returns the array,flattened 返回数组,展开 array([ 2., 8., 0., 6., 4., 5., 1., 1., 8., 9., 3., 6.]) >>> a.reshape(6, 2) #returns the array with a modified shape 返回与改变形状的阵列array([[2.,8.], [0.,6.], [4.,5.], [1.,1.], [8.,9.], [3.,6.]]) >>> a.T #returns the array,transposed 返回数组,转置 array([[ 2., 4., 8.], [ 8., 5., 9.], [ 0., 1., 3.], [ 6., 1., 6.]])>>>a.T.shape(4,3)>>>a.shape(3,4) 由ravel()展平的数组元素的顺序通常是“C风格”的,就是说,最右边的索引变化得最快,所以元素a[0,0]之后是a[0,1]。如果数组被改变形状(reshape)成其它形状,数组仍然是“C风格”的。NumPy通常创建一个以这个顺序保存数据的数组,所以ravel()将总是不需要复制它的参数。但是如果数组是通过切片其它数组或有不同寻常的选项时,它可能需要被复制。函数reshape()和ravel()还可以被同过一些可选参数构建成FORTRAN风格的数组,即最左边的索引变化最快。 reshape函数改变参数形状并返回它,而resize函数改变数组自身。 >>> a array([[ 2., 8.,0., 6.], [ 4.,5., 1., 1.], [8., 9.,3., 6.]]) >>> a.resize((2,6)) >>> a array([[ 2., 8., 0., 6., 4., 5.], [ 1., 1., 8., 9., 3., 6.]]) >>> a.reshape(3,-1) #如果在改变形状操作中一个维度被给做-1,其维度将自动被计算 array([[ 2., 8.,0., 6.], [ 4.,5., 1., 1.], [ 8.,9., 3., 6.]]) 更多 shape, reshape, resize, ravel 参考NumPy示例 组合(stack)不同的数组 几种方法可以沿不同轴将数组堆叠在一起: >>> a = floor(10*np.random.random((2,2))) >>> a array([[ 1., 1.], [ 5., 8.]]) >>> b = floor(10*random.random((2,2))) >>> b array([[ 3., 3.], [ 6., 0.]]) >>> vstack((a,b)) array([[ 1., 1.], [ 5., 8.], [ 3., 3.], [ 6., 0.]]) >>> hstack((a,b)) array([[ 1., 1., 3., 3.], [ 5., 8., 6., 0.]]) 函数column_stack以列将一维数组合成二维数组,它等同与vstack对一维数组。 >>> np.column_stack((a,b)) # With 2D arrays array([[ 1., 1., 3., 3.], [ 5., 8., 6., 0.]]) >>> a=np.array([4.,2.]) >>> b=np.array([2.,8.]) >>> a[:,newaxis] # This allows to have a 2D columns vector array([[ 4.], [ 2.]]) >>> np.column_stack((a[:,newaxis],b[:,newaxis])) array([[ 4., 2.], [ 2., 8.]]) >>> np.vstack((a[:,newaxis],b[:,newaxis])) # The behavior of vstack is different array([[ 4.], [ 2.], [ 2.], [ 8.]]) row_stack函数,另一方面,将一维数组以行组合成二维数组。 对那些维度比二维更高的数组,hstack沿着第二个轴组合,vstack沿着第一个轴组合,concatenate允许可选参数给出组合时沿着的轴。 Note 在复杂情况下,r_[]和c_[]对创建沿着一个方向组合的数很有用,它们允许范围符号(“:”): >>> np.r_[1:4,0,4] array([1, 2, 3, 0, 4]) 当使用数组作为参数时,r_和c_的默认行为和vstack和hstack很像,但是允许可选的参数给出组合所沿着的轴的代号。 更多函数hstack , vstack, column_stack , row_stack , concatenate , c_ , r_ 参见NumPy示例. 将一个数组分割(split)成几个小数组 使用hsplit你能将数组沿着它的水平轴分割,或者指定返回相同形状数组的个数,或者指定在哪些列后发生分割: >>> a = np.floor(10*np.random.random((2,12))) >>> a array([[ 8., 8., 3., 9., 0., 4., 3., 0., 0., 6., 4., 4.], [ 0., 3., 2., 9., 6., 0., 4., 5., 7., 5., 1., 4.]]) >>> np.hsplit(a,3) # Split a into 3 [array([[ 8., 8., 3., 9.], [ 0., 3., 2., 9.]]), array([[ 0., 4., 3., 0.], [ 6., 0., 4., 5.]]), array([[ 0., 6., 4., 4.], [ 7., 5., 1., 4.]])] >>> np.hsplit(a,(3,4)) # Split a after the third and the fourth column [array([[ 8., 8., 3.], [ 0., 3., 2.]]), array([[ 9.], [ 9.]]), array([[ 0., 4., 3., 0., 0., 6., 4., 4.], [ 6., 0., 4., 5., 7., 5., 1., 4.]])] vsplit沿着纵向的轴分割,array split允许指定沿哪个轴分割。 复制和视图 当运算和处理数组时,它们的数据有时被拷贝到新的数组有时不是。这通常是新手的困惑之源。这有三种情况: 完全不拷贝 简单的赋值不拷贝数组对象或它们的数据。 >>> a = np.arange(12) >>> b = a # no new object is created >>> b is a # a and b are two names for the same ndarray object True >>> b.shape = 3,4 # changes the shape of a >>> a.shape (3, 4) Python 传递不定对象作为参考,所以函数调用不拷贝数组。 >>> def f(x): ... print(id(x)) ... >>> id(a) # id is a unique identifier of an object 148293216 >>> f(a) 148293216 视图(view)和浅复制 不同的数组对象分享同一个数据。视图方法创造一个新的数组对象指向同一数据。 >>> c = a.view() >>> c is a False >>> c.base is a # c is a view of the data owned by a True >>> c.flags.owndata False >>> >>> c.shape = 2,6 # a's shape doesn't change >>> a.shape (3, 4) >>> c[0,4] = 1234 # a's data changes >>> a array([[ 0, 1, 2, 3], [1234, 5, 6, 7], [ 8, 9, 10, 11]]) 切片数组返回它的一个视图: >>> s = a[ : , 1:3] # spaces added for clarity; could also be written "s = a[:,1:3]" >>> s[:] = 10 # s[:] is a view of s. Note the difference between s=10 and s[:]=10 >>> a array([[ 0, 10, 10, 3], [1234, 10, 10, 7], [ 8, 10, 10, 11]]) 深复制 这个复制方法完全复制数组和它的数据。 >>> d = a.copy() # a new array object with new data is created >>> d is a False >>> d.base is a # d doesn't share anything with a False >>> d[0,0] = 9999 >>> a array([[ 0, 10, 10, 3], [1234, 10, 10, 7], [ 8, 10, 10, 11]]) 函数和方法(method)总览 这是个NumPy函数和方法分类排列目录。这些名字链接到NumPy示例,你可以看到这些函数起作用。[^5] 创建数组 arange,array,copy,empty,empty_like,eye,fromfile,fromfunction,identity,linspace,logspace,mgrid,ogrid,ones, ones_like,r,zeros,zeros_like 转化 ndarray.astype,atleast_1d,atleast_2d,atleast_3d,mat 操作 array_split,column_stack,concatenate,diagonal,dsplit,dstack,hsplit,hstack,ndarray.item,newaxis,ravel,repeat, reshape,resize,squeeze,swapaxes,take,transpose,vsplit,vstack 询问 all,any,nonzero,where 排序 argmax,argmin,argsort,max,min,ptp,searchsorted,sort 运算 choose,compress,cumprod,cumsum,inner,ndarray.fill,imag,prod,put,putmask,real,sum 基本统计 cov,mean,std,var 基本线性代数 cross,dot,outer,linalg.svd,vdot 进阶 广播法则(rule) 广播法则能使通用函数有意义地处理不具有相同形状的输入。 广播第一法则是,如果所有的输入数组维度不都相同,一个“1”将被重复地添加在维度较小的数组上直至所有的数组拥有一样的维度。 广播第二法则确定长度为1的数组沿着特殊的方向表现地好像它有沿着那个方向最大形状的大小。对数组来说,沿着那个维度的数组元素的值理应相同。 应用广播法则之后,所有数组的大小必须匹配。更多细节可以从这个文档找到。 花哨的索引和索引技巧 NumPy比普通Python序列提供更多的索引功能。除了索引整数和切片,正如我们之前看到的,数组可以被整数数组和布尔数组索引。 通过数组索引 >>> a = np.arange(12)**2 # the first 12 square numbers >>> i = np.array( [ 1,1,3,8,5 ] ) # an array of indices >>> a[i] # the elements of a at the positions i array([ 1, 1, 9, 64, 25]) >>> >>> j = np.array( [ [ 3, 4], [ 9, 7 ] ] ) # a bidimensional array of indices >>> a[j] # the same shape as j array([[ 9, 16], [81, 49]]) 当被索引数组a是多维的时,每一个唯一的索引数列指向a的第一维。以下示例通过将图片标签用调色版转换成色彩图像展示了这种行为。 >>> palette = np.array( [ [0,0,0], # black ... [255,0,0], # red ... [0,255,0], # green ... [0,0,255], # blue ... [255,255,255] ] ) # white >>> image = np.array( [ [ 0, 1, 2, 0 ], # each value corresponds to a color in the palette ... [ 0, 3, 4, 0 ] ] ) >>> palette[image] # the (2,4,3) color image array([[[ 0, 0, 0], [255, 0, 0], [ 0, 255, 0], [ 0, 0, 0]], [[ 0, 0, 0], [ 0, 0, 255], [255, 255, 255], [ 0, 0, 0]]]) 我们也可以给出不不止一维的索引,每一维的索引数组必须有相同的形状。 >>> a = np.arange(12).reshape(3,4) >>> a array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> i = np.array( [ [0,1], # indices for the first dim of a ... [1,2] ] ) >>> j = np.array( [ [2,1], # indices for the second dim ... [3,3] ] ) >>> >>> a[i,j] # i and j must have equal shape array([[ 2, 5], [ 7, 11]]) >>> >>> a[i,2] array([[ 2, 6], [ 6, 10]]) >>> >>> a[:,j] # i.e., a[ : , j] array([[[ 2, 1], [ 3, 3]], [[ 6, 5], [ 7, 7]], [[10, 9], [11, 11]]]) 自然,我们可以把i和j放到序列中(比如说列表)然后通过list索引。 >>> l = [i,j] >>> a[l] # equivalent to a[i,j] array([[ 2, 5], [ 7, 11]]) 然而,我们不能把i和j放在一个数组中,因为这个数组将被解释成索引a的第一维。 >>> s = np.array( [i,j] ) >>> a[s] # not what we want --------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-100-b912f631cc75> in <module>() ----> 1 a[s] IndexError: index (3) out of range (0<=index<2) in dimension 0 >>> >>> a[tuple(s)] # same as a[i,j] array([[ 2, 5], [ 7, 11]]) 另一个常用的数组索引用法是搜索时间序列最大值6。 >>> time = np.linspace(20, 145, 5) # time scale >>> data = np.sin(np.arange(20)).reshape(5,4) # 4 time-dependent series >>> time array([ 20. , 51.25, 82.5 , 113.75, 145. ]) >>> data array([[ 0. , 0.84147098, 0.90929743, 0.14112001], [-0.7568025 , -0.95892427, -0.2794155 , 0.6569866 ], [ 0.98935825, 0.41211849, -0.54402111, -0.99999021], [-0.53657292, 0.42016704, 0.99060736, 0.65028784], [-0.28790332, -0.96139749, -0.75098725, 0.14987721]]) >>> >>> ind = data.argmax(axis=0) # index of the maxima for each series >>> ind array([2, 0, 3, 1]) >>> >>> time_max = time[ ind] # times corresponding to the maxima >>> >>> data_max = data[ind, xrange(data.shape[1])] # => data[ind[0],0], data[ind[1],1]... >>> >>> time_max array([ 82.5 , 20. , 113.75, 51.25]) >>> data_max array([ 0.98935825, 0.84147098, 0.99060736, 0.6569866 ]) >>> >>> np.all(data_max == data.max(axis=0)) True 你也可以使用数组索引作为目标来赋值: >>> a = np.arange(5) >>> a array([0, 1, 2, 3, 4]) >>> a[[1,3,4]] = 0 >>> a array([0, 0, 2, 0, 0]) 然而,当一个索引列表包含重复时,赋值被多次完成,保留最后的值: >>> a = np.arange(5) >>> a[[0,0,2]]=[1,2,3] >>> a array([2, 1, 3, 3, 4]) 这足够合理,但是小心如果你想用Python的+=结构,可能结果并非你所期望: >>> a = np.arange(5) >>> a[[0,0,2]]+=1 >>> a array([1, 1, 3, 3, 4]) 即使0在索引列表中出现两次,索引为0的元素仅仅增加一次。这是因为Python要求a+=1和a=a+1等同。 通过布尔数组索引 当我们使用整数数组索引数组时,我们提供一个索引列表去选择。通过布尔数组索引的方法是不同的我们显式地选择数组中我们想要和不想要的元素。 我们能想到的使用布尔数组的索引最自然方式就是使用和原数组一样形状的布尔数组。 >>> a = np.arange(12).reshape(3,4) >>> b = a > 4 >>> b # b is a boolean with a's shape array([[False, False, False, False], [False, True, True, True], [True, True, True, True]], dtype=bool) >>> a[b] # 1d array with the selected elements array([ 5, 6, 7, 8, 9, 10, 11]) 这个属性在赋值时非常有用: >>> a[b] = 0 # All elements of 'a' higher than 4 become 0 >>> a array([[0, 1, 2, 3], [4, 0, 0, 0], [0, 0, 0, 0]]) 你可以参考曼德博集合示例看看如何使用布尔索引来生成曼德博集合的图像。 >>> import numpy as np >>> import matplotlib.pyplot as plt >>> def mandelbrot( h,w, maxit=20 ): ... """Returns an image of the Mandelbrot fractal of size (h,w).""" ... y,x = np.ogrid[ -1.4:1.4:h*1j, -2:0.8:w*1j ] ... c = x+y*1j ... z = c ... divtime = maxit + np.zeros(z.shape, dtype=int) ... ... for i in range(maxit): ... z = z**2 + c ... diverge = z*np.conj(z) > 2**2 # who is diverging ... div_now = diverge & (divtime==maxit) # who is diverging now ... divtime[div_now] = i # note when ... z[diverge] = 2 # avoid diverging too much ... ... return divtime >>> plt.imshow(mandelbrot(400,400)) >>> plt.show() 第二种通过布尔来索引的方法更近似于整数索引;对数组的每个维度我们给一个一维布尔数组来选择我们想要的切片。 >>> a = np.arange(12).reshape(3,4) >>> b1 = np.array([False,True,True]) # first dim selection >>> b2 = np.array([True,False,True,False]) # second dim selection >>> >>> a[b1,:] # selecting rows array([[ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> >>> a[b1] # same thing array([[ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> >>> a[:,b2] # selecting columns array([[ 0, 2], [ 4, 6], [ 8, 10]]) >>> >>> a[b1,b2] # a weird thing to do array([ 4, 10]) 注意一维数组的长度必须和你想要切片的维度或轴的长度一致,在之前的例子中,b1是一个秩为1长度为三的数组(a的行数),b2(长度为4)与a的第二秩(列)相一致。7 ix_()函数 ix_函数可以为了获得多元组的结果而用来结合不同向量。例如,如果你想要用所有向量a、b和c元素组成的三元组来计算a+b*c: >>> a = np.array([2,3,4,5]) >>> b = np.array([8,5,4]) >>> c = np.array([5,4,6,8,3]) >>> ax,bx,cx = np.ix_(a,b,c) >>> ax array([[[2]], [[3]], [[4]], [[5]]]) >>> bx array([[[8], [5], [4]]]) >>> cx array([[[5, 4, 6, 8, 3]]]) >>> ax.shape, bx.shape, cx.shape ((4, 1, 1), (1, 3, 1), (1, 1, 5)) >>> result = ax+bx*cx >>> result array([[[42, 34, 50, 66, 26], [27, 22, 32, 42, 17], [22, 18, 26, 34, 14]], [[43, 35, 51, 67, 27], [28, 23, 33, 43, 18], [23, 19, 27, 35, 15]], [[44, 36, 52, 68, 28], [29, 24, 34, 44, 19], [24, 20, 28, 36, 16]], [[45, 37, 53, 69, 29], [30, 25, 35, 45, 20], [25, 21, 29, 37, 17]]]) >>> result[3,2,4] 17 >>> a[3]+b[2]*c[4] 17 你也可以实行如下简化: def ufunc_reduce(ufct, *vectors): vs = np.ix_(*vectors) r = ufct.identity for v in vs: r = ufct(r,v) return r 然后这样使用它: >>> ufunc_reduce(np.add,a,b,c) array([[[15, 14, 16, 18, 13], [12, 11, 13, 15, 10], [11, 10, 12, 14, 9]], [[16, 15, 17, 19, 14], [13, 12, 14, 16, 11], [12, 11, 13, 15, 10]], [[17, 16, 18, 20, 15], [14, 13, 15, 17, 12], [13, 12, 14, 16, 11]], [[18, 17, 19, 21, 16], [15, 14, 16, 18, 13], [14, 13, 15, 17, 12]]]) 这个reduce与ufunc.reduce(比如说add.reduce)相比的优势在于它利用了广播法则,避免了创建一个输出大小乘以向量个数的参数数组。8 用字符串索引 参见RecordArray。 线性代数 继续前进,基本线性代数包含在这里。 简单数组运算 参考numpy文件夹中的linalg.py获得更多信息 >>> import numpy as np >>> a = np.array([[1.0, 2.0], [3.0, 4.0]]) >>> print(a) [[ 1. 2.] [ 3. 4.]] >>> a.transpose() array([[ 1., 3.], [ 2., 4.]]) >>> np.linalg.inv(a) array([[-2. , 1. ], [ 1.5, -0.5]]) >>> u =np.eye(2) # unit 2x2 matrix; "eye" represents "I" >>> u array([[ 1., 0.], [ 0., 1.]]) >>> j = np.array([[0.0, -1.0], [1.0, 0.0]]) >>> np.dot (j, j) # matrix product array([[-1., 0.], [ 0., -1.]]) >>> np.trace(u) # trace 2.0 >>> y = np.array([[5.], [7.]]) >>> np.linalg.solve(a, y) array([[-3.], [ 4.]]) >>> np.linalg.eig(j) (array([ 0.+1.j, 0.-1.j]), array([[ 0.70710678+0.j, 0.70710678+0.j], [ 0.00000000-0.70710678j, 0.00000000+0.70710678j]])) Parameters: square matrix Returns The eigenvalues, each repeated according to its multiplicity. The normalized (unit "length") eigenvectors, such that the column ``v[:,i]`` is the eigenvector corresponding to the eigenvalue ``w[i]`` . 技巧和提示 下面我们给出简短和有用的提示。 “自动”改变形状 更改数组的维度,你可以省略一个尺寸,它将被自动推导出来。 >>> a = np.arange(30) >>> a.shape = 2,-1,3 # -1 means "whatever is needed" >>> a.shape (2, 5, 3) >>> a array([[[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11], [12, 13, 14]], [[15, 16, 17], [18, 19, 20], [21, 22, 23], [24, 25, 26], [27, 28, 29]]]) 向量组合(stacking) 我们如何用两个相同尺寸的行向量列表构建一个二维数组?在MATLAB中这非常简单:如果x和y是两个相同长度的向量,你仅仅需要做m=[x;y]。在NumPy中这个过程通过函数column_stack、dstack、hstack和vstack来完成,取决于你想要在那个维度上组合。例如: x = np.arange(0,10,2) # x=([0,2,4,6,8]) y = np.arange(5) # y=([0,1,2,3,4]) m = np.vstack([x,y]) # m=([[0,2,4,6,8], # [0,1,2,3,4]]) xy = np.hstack([x,y]) # xy =([0,2,4,6,8,0,1,2,3,4]) 二维以上这些函数背后的逻辑会很奇怪。 参考写个Matlab用户的NumPy指南并且在这里添加你的新发现: ) 直方图(histogram) NumPy中histogram函数应用到一个数组返回一对变量:直方图数组和箱式向量。注意:matplotlib也有一个用来建立直方图的函数(叫作hist,正如matlab中一样)与NumPy中的不同。主要的差别是pylab.hist自动绘制直方图,而numpy.histogram仅仅产生数据。 import numpy as np import matplotlib.pyplot as plt # Build a vector of 10000 normal deviates with variance 0.5^2 and mean 2 mu, sigma = 2, 0.5 v =np.random.normal(mu,sigma,10000) # Plot a normalized histogram with 50 bins plt.hist(v, bins=50, normed=1) # matplotlib version (plot) pylab.show() # Compute the histogram with numpy and then plot it (n, bins) = numpy.histogram(v, bins=50, normed=True) # NumPy version (no plot) plt.plot(.5*(bins[1:]+bins[:-1]), n) plt.show() >>> # Compute the histogram with numpy and then plot it >>> (n, bins) = np.histogram(v, bins=50, normed=True) # NumPy version (no plot) >>> plt.plot(.5*(bins[1:]+bins[:-1]), n) >>> plt.show() Numpy/Scipy官网: https://www.scipy.org/ Numpy英文版官方快速入门教程: https://docs.scipy.org/doc/numpy-dev/user/quickstart.html#an-example

优秀的个人博客,低调大师

Python3网络爬虫——(2)设置User Agent模拟浏览器访问

设置User Agent模拟浏览器访问 方法一、使用build_opener()修改报头 # -*- coding: UTF-8 -*- #使用build_opener()修改报头 from urllib import request if __name__ == "__main__": url="https://blog.csdn.net/asialee_bird/article/details/79673860" headers=("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.168 Safari/537.36") opener=request.build_opener() opener.addheaders=[headers] file=opener.open(url) data=file.read() print(data) 方法二、使用add_header修改报头 # -*- coding: UTF-8 -*- #使用add_header修改报头 from urllib import request if __name__ == "__main__": url="https://blog.csdn.net/asialee_bird/article/details/79673860" req=request.Request(url) #创建一个Request对象 req.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.168 Safari/537.36") file=request.urlopen(req) data=file.read() data=data.decode('utf-8') #对读取的信息进行解码 print(data) 结果: 方法三、 # -*- coding: UTF-8 -*- from urllib import request if __name__ == "__main__": #以CSDN为例,CSDN不更改User Agent是无法访问的 url = 'http://www.csdn.net/' head = {} #写入User Agent信息 head['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.168 Safari/537.36' req = request.Request(url, headers=head) #创建Request对象 response = request.urlopen(req) #传入创建好的Request对象 html = response.read().decode('utf-8') #读取响应信息并解码 print(html) #打印信息 注: 常见的User Agent 1.Android Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19 Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 Mozilla/5.0 (Linux; U; Android 2.2; en-gb; GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 2.Firefox Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0 Mozilla/5.0 (Android; Mobile; rv:14.0) Gecko/14.0 Firefox/14.0 3.Google Chrome Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36 Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19 4.iOS Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3 Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A101a Safari/419.3 上面列举了Andriod、Firefox、Google Chrome、iOS的一些User Agent,直接copy就能用

优秀的个人博客,低调大师

Python3在指定路径下递归定位文件中出现的字符串

[本文出自天外归云的博客园] 脚本功能:在指定的路径下递归搜索,找出指定字符串在文件中出现的位置(行信息)。 用到的python特性: 1. PEP 318 -- Decorators for Functions and Methods 2. PEP 380 -- Syntax for Delegating to a Subgenerator 3.PEP 471 -- os.scandir() function -- a better and faster directory iterator 4.PEP 498 -- Literal String Interpolation 代码如下: import os import sys __all__ = ['DirPath'] ''' 在指定路径下递归查找包含指定字符串的文件 可以指定查找的文件类型category-默认为'.py' 可以指定查找的字符串str-默认为'python' ''' class DirPath(object): # 初始化参数查找路径-path def __init__(self, path): self.show = self.show() self.path = path # 开启func协程的装饰器 def on(func): def wrapper(*args): res = func(*args) next(res) return res return wrapper @on # 搜索path路径下的python文件 def search(self, target, category): while True: path = yield for entry in os.scandir(path): if entry.is_file(): if entry.name.endswith(category): target.send(entry.path) if entry.is_dir(): self.search(target, category).send(entry.path) @on # 找到f文件中包含str的行信息并发送给target def find_str(self, target, str): while True: path = yield with open(path, "r", encoding='utf-8') as f: for (name, value) in enumerate(f): if str in value: target.send(f"[{path}][{name+1}]:{value}") @on # 展示查询结果 def show(self): while True: res = yield print(res) # 默认在'.py'类型文件中查找字符串-可以指定文件类型category # 默认查找字符串'python'-可以指定查找字符串str def code_search(self, category=".py", str="python"): self.search(self.find_str(self.show, str), category).send(self.path) if __name__ == '__main__': path = sys.argv[1] Dir = DirPath(path) Dir.code_search(str=sys.argv[2], category=sys.argv[3]) 本地运行脚本,搜索结果示例如下:

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册