摘要:
#一般如果想使用索引访问元素时,就可以在类中定义这个方法(__getitem__(self, key) )class Foo(object): def __init__(self): self.data = {} def __getitem__(self, key): print('__getite 阅读全文
摘要:
#f = open("yesterday2",'r+',encoding="utf-8") #文件句柄 读写#f = open("yesterday2",'w+',encoding="utf-8") #文件句柄 写读#f = open("yesterday2",'a+',encoding="utf- 阅读全文
摘要:
#coding=utf-8 a = "你" # 这个字符串是Unicode和 a = u“你”等价b = b'\\u4f60' #这个表示b是字节串(如果需要显示b的值则 print(b.decode("unicode-escape")) )系统会返回“你”这个值是因为它根据utf-8来给你解码pr 阅读全文
摘要:
来源:http://www.jb51.net/article/92006.htm 以下是全文: 这两天写了个监测网页的爬虫,作用是跟踪一个网页的变化,但运行了一晚出现了一个问题。。。。希望大家不吝赐教!我用的是python3,错误在对html response的decode时抛出,代码原样为: re 阅读全文
摘要:
import sys,timefor i in range(10): sys.stdout.write("#") sys.stdout.flush() #不一次次刷新会导致一次性写完后才显示 time.sleep(0.5) 阅读全文
摘要:
list_1 = [1,4,5,7,3,6,7,9]list_1 = set(list_1)list_2 =set([2,6,0,66,22,8,4])print(list_1,list_2)'''#交集print( list_1.intersection(list_2) )#并集print(lis 阅读全文
摘要:
name = "my \tname is {name} and i am {year} old" print(name.capitalize())name的首字母大写print(name.count("a")) name中a的数量print(name.center(50,"-"))总共打印50个字符 阅读全文
摘要:
person=['aaa',['a',bbb'] p1=copy.copy(person) p2=person[:] p3=list(person) p4=person.copy() print(type(p1)) 查看p1是什么格式,如int,str num.isdigit() 判断是否是全数字组 阅读全文