随笔分类 - python
摘要:while True: id = input('请输入ID(如1001):') if not id: break开始不明白 if not id是什么用法,我输入什么都一直循环,后面发现一个帖子,说 在python中None,False,空字符串,空列表,空字典,空元组都相当于False,X是他们,n
阅读全文
摘要:一、在浏览器中将 Headers复制到pycharm的py文件中 Host: beacon.tingyun.comConnection: keep-aliveContent-Length: 2988Sec-Fetch-Dest: emptyUser-Agent: Mozilla/5.0 (Windo
阅读全文
摘要:pip config set global.index-url 源链接例:pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/ 换回默认源 pip config unset global.index-url
阅读全文
摘要:db=pymysql.connect("ip地址","用户名","密码","数据库")cursor=db.cursor()cursor.execute("select * from zj_class limit 5")data=cursor.fetchall()for i in range(5):
阅读全文
摘要:读excel 1、导入模块 import xlrd 2、打开Excel文件读取数据 data = xlrd.open_workbook('excel.xls') 3、获取一个工作表 ① table = data.sheets()[0] #通过索引顺序获取② table = data.sheet_by
阅读全文
摘要:r+就是以可读写方式打开文件,文件必须存在w+ 打开可读写文件,若文件存在则文件长度清为零,即该文件内容会消失。若文件不存在则建立该文件。 将数据写入文件后需要先关闭,然后再读出来
阅读全文
摘要:a=[1,2,3,1,3]print list(set(a))
阅读全文
摘要:记事本默认是ANSI的默认是GBK,需要转码,见下:
阅读全文
摘要:abcd,123,789 将字符串拼接用join,Join前面的逗号是拼接时的分隔符 拼接时注意Join里面是列表 Python replace()方法 描述 Python replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过
阅读全文
摘要:print "my name is: %s" %"xiaoming"结果:my name is: xiaoming后面跟2个参数,可以用小括号,3个参数也是在括号中加 print "my name is: %s %d"%("33",55)结果:my name is: 33 55用format格式 a
阅读全文
摘要:默认是asc码,想得到汉字的真实长度要先转换成unicode型。看下面的例子。 a="abcd" print len(a) 结果:4 a="哈哈" print len(a) 结果:6 一个汉字占3个字节 怎么让a的长度是2呢,两种方法: 方法一:a=u"哈哈" 方法二:a="哈哈".decode('
阅读全文
摘要:在做接口测试时,有时候返回的Json串中显示unicode码,如:‘\u53eb\u6211’,进行反编码后得到其对应的汉字。 f='\u4f18\u8863\u5e93\u4fc3\u9500' print f print(f.decode('unicode-escape')) 结果:优衣库促销
阅读全文
摘要:#!coding=utf-8 import urllib import urllib2 data='{"":""}' data={data:""} data=urllib.urlencoce(data) url='' request=urllib2.Request(url,data) respons
阅读全文
摘要:如果我们需要获取字典值的话,我们有两种方法,一个是通过dict['key'],另外一个就是dict.get()方法。今天给大家分享的就是字典的get()方法。这里我们可以用字典做一个小游戏,假设用户在终端输入字符串:"1"或者是"2"或者是"3",返回对应的内容,如果是输入其他的,则返回"error
阅读全文
摘要:import urllib,urlparseurl = urlparse.urlunsplit(("http","lmbtfy.bangbang93.com","/",urllib.quote("百度一下"),""))print (url)
阅读全文
浙公网安备 33010602011771号