Python中的连接符(+、+=)示例详解
前言本文通过在一段示例代码中发现的问题,来给大家详细介绍了python中的连接符(+、+=),下面话不多说,来看详细的介绍吧。假设有下面一段代码:a = [1, 2, 3, 4]b = [5, 6, 7, 8, 9]c = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]for item in (a, b, c): item += [0] * (10 -...
View ArticlePython中datetime模块参考手册
前言python提供了多个内置模块用于操作日期时间,像 calendar,time,datetime。time模块提供的接口与C标准库 time.h 基本一致。相比于 time 模块,datetime模块的接口则更直观、更容易调用。模块定义了两个常量: datetime.MINYEAR datetime.MAXYEAR 这两个常量分别表示 datetime...
View Articlepython 计算文件的md5值实例
较小文件处理方法:import hashlibimport osdef get_md5_01(file_path): md5 = None if os.path.isfile(file_path): f = open(file_path,'rb') md5_obj = hashlib.md5() md5_obj.update(f.read()) hash_code =...
View ArticlePython 字典与字符串的互转实例
字典转换为字符串if __name__ == '__main__': a = {'a' : 1, 'b' : 2, 'c' : 3} b = str(a) print(type(b))输出结果为:<class 'str'>---------------------------------------------------------------字符串转换为字典if __name__...
View Articlepython 安装virtualenv和virtualenvwrapper的方法
1. 首先介绍pip常用命令pip安装命令: pip install package_name pip升级命令:pip install Cungrage package_name pip卸载命令:pip uninstall package_name如 pip install django pip install -U django2. virtualenv的安装virtualenv的安装:$...
View ArticlePython 使用os.remove删除文件夹时报错的解决方法
os.remove不能用来删除文件夹,否则拒绝访问。# -*- coding:utf-8 -*-import osif __name__ == "__main__": os.remove('D:\\test')运行结果:删除空目录:# -*- coding:utf-8 -*-import osif __name__ == "__main__":...
View Articlepython递归删除指定目录及其所有内容的方法
实例如下:#! /usr/bin/python# -*- coding: utf-8 -*-import osdef del_dir_tree(path): ''' 递归删除目录及其子目录, 子文件''' if os.path.isfile(path): try: os.remove(path) except Exception, e: #pass print e elif...
View ArticlePython实现二分查找与bisect模块详解
前言其实python 的列表(list)内部实现是一个数组,也就是一个线性表。在列表中查找元素可以使用 list.index() 方法,其时间复杂度为O(n) 。对于大数据量,则可以用二分查找进行优化。二分查找要求对象必须有序,其基本原理如下: 1.从数组的中间元素开始,如果中间元素正好是要查找的元素,则搜素过程结束;...
View ArticleDeal: Certified Professional Data Science with Python Bundle for $49 1/20/17
Before most people make business decisions, it’s important to take a look at data and see how these decisions might affect you and/or your business. Well now you can take a course and become certified...
View ArticleInfinit's build system: Drake
In April 2016, we started our open-sourcing process by releasing a fork of Infinit's technical leader's (Quentin mefyl Hocquet) build system: Drake . Drake is a language agnostic build-system,...
View ArticlePyTennessee: PyTN Profiles:Daniel Pritchett and TechFed Nashville
Speaker Profile: Daniel Pritchett Hailing from Memphis, Tennessee, Daniel is a longtime consulting developer with a fondness for dynamic languages and the Unix command line. Daniel’s production...
View Article使用Python分析纽约出租车搭乘数据
在纽约,出租车分为两类:黄色和绿色。黄色出租(Yellow TAXI)车可以在纽约五大区(布朗克斯区、布鲁克林区、曼哈顿、皇后区、斯塔滕岛)内任何地点搭载乘客。绿色出租车(Green TAXI)则被规定只允许在上曼哈顿、布朗克斯区、皇后区和斯塔滕岛接客,这两类出租车均由私人公司经营并受到纽约市出租车和轿车委员会(NYC Taxi and Limousine...
View ArticleShort-Circuit Operators in Python
In python short circuiting is supported by various boolean operators and functions. By short circuiting we mean the stoppage of execution of boolean operation if the truth value of expression has been...
View ArticlePython 之旅
在学习和使用 python 的过程中,我作了不少笔记,并对一些笔记进行了加工和完善,发表在博客上。随着笔记的增加,我就萌生了写一本书的想法,希望能比较系统地总结相关知识,巩固自己的知识体系,而不是停留在『感觉好像懂了』的状态中。 有了想法之后,接下来就要开始写了。当然,从产生想法到付诸实践还是纠结了一段时间,毕竟,作笔记和写书很不一样啊。思想斗争过后,我下定决心要把它写出来。...
View ArticlePhorth: a forth-like language on the Python VM
phorth phorth is a bootstrapped forth-like language where instead of writing our primitive words in some assembler, we have chosen to write them in a mix of Cpython bytecode and C++*. By using a...
View ArticleDitch your bucket of scripts for a tool belt
If you’re like us at Nextdoor, you have a lot of scripts that do a lot of useful things. Maybe, like us, you have some wiki pages that tells you the full path names of these scripts and the situations...
View ArticlePipenv: Sacred Marriage of Pipfile, Pip, & Virtualenv
Pipenv: Sacred Marriage of Pipfile, Pip, & Virtualenv Pipenv is an experimental project that aims to bring the best of all packaging worlds to the python world. It harnesses Pipfile , pip, and...
View ArticlePython 详解基本语法_函数_返回值
python 详解基本语法概要:函数的返回值是函数重要的组成部分。函数的根本在于实现程序的部分功能,所以很多时候我们需要将函数执行后的结果返回给程序再由程序作出进一步的操作。可以说是函数的返回值令函数与函数之间,函数与主程序之间更加紧密的联系起来。函数的返回值在Python的函数中都有一个返回值,默认为None。也可以使用return...
View ArticlePython 数据结构之队列的实现
python 队列Queue 队列是一种先进先出(FIFO)的数据类型, 新的元素通过 入队 的方式添加进 Queue 的末尾, 出队 就是从 Queue 的头部删除元素.用列表来做 Queue:queue = [] # 初始化一个列表数据类型对象, 作为一个队列def enQ(): # 定义一个入栈方法 queue.append(raw_input('Enter New String:...
View ArticlePython 数据结构之堆栈实例代码
python 堆栈堆栈是一个后进先出(LIFO)的数据结构. 堆栈这个数据结构可以用于处理大部分具有后进先出的特性的程序流 . 在堆栈中, push 和 pop 是常用术语: push: 意思是把一个对象入栈. pop: 意思是把一个对象出栈.下面是一个由 Python 实现的简单的堆栈结构:stack = [] # 初始化一个列表数据类型对象, 作为一个栈def pushit(): #...
View Article