随笔分类 - python
摘要:class Dog(object): __first_new = True __instance = None def __new__(cls): if cls.__first_new: cls.__instance = object.__new__(cls) ...
阅读全文
摘要:pip install simplejson
阅读全文
摘要:>>> import bisect >>> scores = [(100, 'perl'), (200, 'tcl'), (400, 'lua'), (500, 'python')] >>> bisect.insort(scores, (300, 'ruby')) >>> scores [(100, 'perl'), (200, 'tcl'), (300, 'ruby'), (400, '
阅读全文
摘要:import random INDEXBOX=7 #哈希表元素个数 MAXNUM=13 #数据个数 class Node: #声明链表结构 def __init__(self,val): self.val=val self.next=None global indextable indextable=[Node...
阅读全文
摘要:class Node: #堆栈链结节点的声明 def __init__(self): self.data=0 #堆栈数据的声明 self.next=None #堆栈中用来指向下一个节点 top=None def isEmpty(): global top if(top==None): return 1 e...
阅读全文
摘要:读空的json文件,python2和python3 的错误提示是不一样的 python2: python3: 解决: 针对python2 针对python3
阅读全文
摘要:import yaml yaml_dict={"sss":"111","ddd":"222"} with open("a.yaml", "w") as f: yaml.safe_dump(yaml_dict,f,encoding='utf-8', allow_unicode=True) with open("a.yaml") as f: yaml_dict = yaml.l...
阅读全文
摘要:>>> 'spam eggs' # single quotes 'spam eggs' >>> 'doesn\'t' # use \' to escape the single quote... "doesn't" >>> "doesn't" # ...or use double quotes instead "doesn't" >>> '"Yes,"
阅读全文
摘要:>>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> letters ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> # replace some values >>> letters[2:5] = ['C
阅读全文
摘要:>>> a = ['a', 'b', 'c'] >>> n = [1, 2, 3] >>> x = [a, n] >>> x [['a', 'b', 'c'], [1, 2, 3]] >>> x[0] ['a', 'b', 'c'] >>> x[0][1] 'b'
阅读全文
摘要:第一个元素一定是最小的,如果每次只想拿到列表的最小值,不想整个列表排序,可以通过不断返回最小值的方法实现
阅读全文
摘要:import zipfile import os,shutil import openpyxl file_list_pos="" fileName="" zipfileName="" def un_zip(file_name): """unzip zip file""" zip_file = zipfile.ZipFile(file_name) if o...
阅读全文
摘要:在当前路径解压zip压缩包,生成同名文件夹,内部目录结构与压缩包一致
阅读全文
摘要:import zipfile file_name="a.txt" f = zipfile.ZipFile('test.zip','w',zipfile.ZIP_STORED) f.write(file_name) f.close()
阅读全文
摘要:import glob x=glob.glob('*.py') print(x)
阅读全文
摘要:import itertools original_list = [[2,4,3],[1,5,6], [9], [7,9,0]] new_merged_list = list(itertools.chain(*original_list)) print(new_merged_list)
阅读全文

浙公网安备 33010602011771号