常用方法7月

#-*-coding:utf8-*-
import string
import re
#------------------切割,替换字符串----------------------------------------
s = ‘asdasdgkd‘
dictdata = "{‘name‘:‘hello‘,‘age‘:18}"
# string.replace 替换 s 用空格替换 asd 替换次数为1次
s1 = string.replace(s,"asd","",1)
# re.sub 正则替换
s2 = re.sub("^asd","",s)
#split 切片字符串,结果为list
s3 = s.split("dg")
#eval()将字符串转化为dict 前提是字符串要里面是个字典结果
s5 = eval(dictdata)
print s1,s2,s3,s5
#----------------------------------------------------------

#-----------------------检测网站编码-----------------------------------
#检测网址...编码
rawdata = urllib.urlopen(‘http://www.baidu.com/‘).read()
#检测连接是否成功
resdata = requests.get("http://www.baidu.com")
d = chardet.detect(rawdata)
e = resdata
print d
print e
#----------------------------------------------------------

#-------------------for循环遍历生成列表---------------------------------------
#简洁的for循环
s = ["s={},b={},c={}".format(str(i),str(i+1),str(i+2)) for i in range(20,61,20)]
print s
#----------------------------------------------------------

#-----------------------时间,时间戳-----------------------------------
import time
import datetime
#获取当前时间精确到微秒
print datetime.now()
#time获取当前时间戳
print time.time()
#datetime,将数字转化成时间格式
s = datetime.datetime(2012,6,22)
#mktime将任意时间转为时间戳,中间使用了timetuple将时间格式转化成中间件
print time.mktime(s.timetuple())
#strftime将时间戳转化为时间格式,中间使用了localtime将时间戳转化成中间件
t = time.strftime(‘%Y-%m-%d‘,time.localtime(1467274020.29259))
print t
#----------------------------------------------------------

#----------------------url编码------------------------------------
import chardet
import urllib
#更改dict 的键值
a = {‘a‘:‘%E9%B8%BF%E6%98%9F%E5%B0%94%E5%85%8B‘,‘b‘:{‘c‘:‘b1‘}}
#pop,删除dict中的一项内容键和值
a.pop(‘b‘)
#检查e 的字符编码e是url编码,检测出来是ascii
e = a[‘a‘]
print chardet.detect(e)
#unquote,将url 编码转成中文,quote方法将utf8转url编码
s = urllib.unquote(e)
print chardet.detect(urllib.unquote(e))#utf8
print s#中文
#quote方法将utf8转url编码,检测出来是ascii
print urllib.quote(s)#url编码
print chardet.detect(urllib.quote(s))#ascii
#----------------------------------------------------------

#--------------两个list->组成tuple->存入list->遍历生成dict------------------
url = [‘page={}‘.format(str(i)) for i in range(1,2)]
val = range(1,3)
#zip生成一个个元组直到组不到元组然后组成的list列表
urlv = zip(url,val)
#循环列表生成dict
urldict = dict((urls,val) for urls,val in urlv)
print urldict
#----------------------------------------------------------
时间: 2024-08-10 22:33:57

常用方法7月的相关文章

获取某年某月有多少天 & 常用日期转换

1 private void Form1_Load(object sender, EventArgs e) 2 { 3 DateTime date=System.DateTime.Today;//只有日期 4 //System.DateTime.Now; //日期+时间 5 int year= date.Year; 6 int month=date.Month; 7 8 int daysNum=System.DateTime.DaysInMonth(year,month);//返回某年某月有多少

8月12号=》391页-395页

14.10 使用document对象 document对象既是HTMLDocument类的一个实例,也是DHTML模型中的一个对象.该对象除了可以使用标准DOM模型 的方法之外,还可以使用它如下几个常用方法. close():结束一个通过open方法打开的document对象. open():打开一个document对象. write():向document对象中输出一条字符串,输完后不换行. writeln():向document对象中输出一条字符串,输完后换行. alinkColor.lin

java-String类常用方法解释笔记

参考注释即可. 1 /*H4ckSo1di3r 2015年2月4日 下午11:55:07*/ 2 package Demo; 3 4 public class TestStringClass_测试String类 { 5 6 7 public static void main(String[] args) { 8 9 // ================================================== 10 // 1.String类常用构造方法 11 //String() 无

空间数据挖掘常用方法

问题1:空间数据挖掘有哪些常用方法,举例说明一种方法的原理及应用. 答:空间数据挖掘的常用方法有:统计法,聚类方法,关联规则发掘方法,Rough集方法,神经网络方法,云理论,证据理论,模糊集理论,遗传算法等算法(出自丁信宙,仇环,苏晓庆. 基于云理论的缺损数据推理和预测 山东理工大学学报 2006年11月).除此以外还有老师课件上提到的聚类检测,决策树方法等. 以下对于一些常见模型做一简述: 1.空间分析方法 (Spatial Analysis Approach) 利用GIS的各种空间分析模型和

js常用方法集锦

1.document.write(""); 输出语句2.JS中的注释为//3.传统的HTML文档顺序是:document->html->(head,body)4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或value)6.一个小写转大写的JS:

2014年至今的博文目录(更新至2017年06月12日)

拓扑学中凝聚点的几个等价定义(2017-06-12 07:51) 江苏省2017年高等数学竞赛本二试题(含解答)(2017-06-10 20:59) 裴礼文数学分析中的典型问题与方法第4章一元函数积分学练习(2017-06-10 11:04) 2017年厦门大学第十四届景润杯数学竞赛试卷(数学类)评分标准(2017-06-05 15:31) 2017年华东师范大学数学竞赛(数学类)试题(2017-06-05 15:28) 裴礼文数学分析中的典型问题与方法第3章一元微分学练习(2017-05-30

iOS-OC-基础-NSDate常用方法

NSDate常用方法 /*=============================NSDate日期类的使用=============================*/ // 获取当前时间,获得的时0市区的时间跟北京时间相差8小时 NSDate *currentDate = [NSDate date]; // GMT NSLog(@"currentDate :%@",currentDate); //timeIntervalSince1970 到1970-1-1的秒数,也叫时间戳(NS

jQuery自带的一些常用方法总结

jQuery自带的一些常用方法总结 这篇文章主要介绍了jQuery自带的一些常用方法总结,包括$.trim .$.contains.$.each.$.map.$.inArray.$.extend等,需要的朋友可以参考下 本身方法($.each,$.map,$.contains,$ajax) 常用工具方法 (1)$.trim $.trim方法用于移除字符串头部和尾部多余的空格. 复制代码 代码如下: $.trim(' Hello ') // Hello (2)$.contains $.contai

VA处理日期时间常用方法:

JAVA处理日期时间常用方法: 1.java.util.Calendar  Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR.MONTH.DAY_OF_MONTH.HOUR 等 日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方法.瞬间可用毫秒值来表示,它是距历元(即格林威治标准时间 1970 年 1 月 1 日的 00:00:00.000,格里高利历)的偏移量. 例:  Java代码   1. Calendar cal = Calendar