![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python进阶
Daphar
学习,实践,总结,再学习
专注python,持续精进
展开
-
Python高效编程实战---1、数据结构与算法进阶
一、在list\dict\set中进行筛选在list中筛选: 方法一:[x for x in list if x>10] # 效率更高 方法二:filter(lambda x :x>10,list) # lambda 定义一个匿名函数在dict中筛选: {k: v for k, v in dict.items() if v > 85} # 后面添加条件在...原创 2018-03-27 11:16:25 · 397 阅读 · 0 评论 -
Python高效编程实战---2、对象迭代与反迭代技巧
一、如何实现可迭代对象和迭代器对象# -*- coding: utf-8 -*-import requestsfrom collections import Iterable, Iteratorclass WeatherIterator(Iterator): # 定义迭代器 def __init__(self, cities): self.cities...原创 2018-03-27 11:17:09 · 190 阅读 · 0 评论 -
Python高效编程实战---3、字符串处理技巧
一、如何拆分含有多种分隔符的字符串# 将字符串s分割成列表s = 'abc,eee,weq,e eiu ew weoi|qwei\qe'方案一:用string的split()方法 append和extend都仅只可以接收一个参数,append 任意,甚至是tuple,extend 只能是一个列表 map()它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 ...原创 2018-03-27 11:17:56 · 508 阅读 · 0 评论 -
Python高效编程实战---4、文件IO高效处理技巧
一、如何读写文本文件 # python2 下读写文本文件f = open('txt.txt', 'w')str = 'litaifa' # 实际是字节串str = u'你好,中国' # unicode 串 以/0xff/0xe1形式存在f.write(str.encode('gbk')) # 需要将unicode串进行编码f.close()f = open('txt.t...原创 2018-03-27 11:18:28 · 1960 阅读 · 0 评论 -
Python高效编程实战---5、csv json xml excel高效解析与构建技巧
一、如何读写csv数据from urllib import urlretrieve# urlretrieve('http://finance.yahoo.com/d/quotes.csv?s=000001.sz','pingan1.csv') # 从网址下载文件存到文件中import csvwith open('pingan1.csv','rb') as rf: re...原创 2018-03-27 11:19:14 · 292 阅读 · 0 评论 -
Python高效编程实战---6、类与对象深度技术进阶
一、如何派生内置不可变类型并修改实例化行为 # 将列表变成元组,且只保留大于0的整数class IntTuple(tuple): def __new__(cls, iterable): g = (x for x in iterable if isinstance(x, int) and x > 0) # isinstance()判断x是不是int整数类,...原创 2018-03-27 11:19:51 · 327 阅读 · 0 评论 -
Python高效编程实战---7、并发编程核心技术应用进阶
一、如何使用多线程、线程间通信、线程间事件通信# -*- coding: utf-8 -*-import csvfrom xml.etree.ElementTree import Element, ElementTreeimport requestsfrom StringIO import StringIOfrom threading import Thread, Event...原创 2018-03-27 11:20:15 · 540 阅读 · 0 评论 -
Python高效编程实战---9、浅谈 Python 的 with 语句
引言 with 语句是从 Python 2.5 开始引入的一种与异常处理相关的功能(2.5 版本中要通过 from __future__ import with_statement 导入后才可以使用),从 2.6 版本开始缺省可用(参考 What’s new in Python 2.6? 中 with 语句相关部分介绍)。 with 语句适用于对资源进行访问的场合,确保不管使用过程中是否发...原创 2018-03-27 11:22:05 · 199 阅读 · 0 评论 -
Python高效编程实战---10、百度语音识别
参考:http://ai.baidu.com/docs#/Begin/top参考代码:# -*- coding: utf-8 -*-import requestsimport json# 录音# from record import Recordfrom Record import Recordrecord=Record(channels=1)audioData=re...原创 2018-03-28 09:05:48 · 2047 阅读 · 0 评论