
Python
文章平均质量分 87
screaming
这个作者很懒,什么都没留下…
展开
-
Python pdb
python中有个pdb模块,使python代码也可以像gdb那样进行调试,一般情况下pdb模块可以在代码内直接使用,也可以通过命令行参数的形式添加该模块进行调试(python -m pdb file.py)。在代码中直接使用pdb模块调试时,import pdb模块后,然后在需要调试的代码出添加pdb.set_trace()命令即可,运行程序后,在运行到次代码处会自动停止,进入调试模式。一般转载 2015-11-25 15:09:57 · 1040 阅读 · 0 评论 -
Python Materials
Eric Raymond’s Perl vs PythonDennis Ritchie’s Perl vs PythonPerl vs Python on regex matchingJohn Shipman’s very helpful Quick Reference (not for beginners)Guido van Rossum’s Python style guidePyth转载 2015-11-19 22:34:43 · 551 阅读 · 0 评论 -
Python Decorator
Understanding Python Decorators in 12 Easy Steps!1 July 2012Ok, perhaps I jest. As a Python instructor, understanding decorators is a topic I find studentsconsistently struggle with upon first e转载 2015-11-19 17:00:46 · 809 阅读 · 0 评论 -
Python integer ranges
43 down vote favorite7In Python, is there a way to get the largest integer one can use? Is there some pre-defined constant like INT_MAX?pythoninteger shareimprove转载 2016-01-16 13:00:40 · 765 阅读 · 0 评论 -
Python sort and sorted
我们需要对List进行排序,Python提供了两个方法对给定的List L进行排序,方法1.用List的成员函数sort进行排序方法2.用built-in函数sorted进行排序(从2.4开始)sorted函数是内建函数,他接受一个序列,返回有序的副本他与sort的唯一区别就是会返回副本----------------------------转载 2016-01-02 23:52:11 · 272 阅读 · 0 评论 -
Python List Operation
Python List Examples – Insert, Append, Length, Index, Remove, Popby HIMANSHU ARORA on JUNE 21, 2013TweetLists in Python language can be compared to arrays in Java but they ar转载 2016-01-03 00:35:45 · 762 阅读 · 0 评论 -
Python List Comprehensions
An Introduction to List Comprehensions in PythonTweetThe basics.Let’s start with a simple list.>>> my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>>> my_list[1, 2, 3, 4, 5, 6, 7,转载 2016-01-03 15:33:17 · 393 阅读 · 0 评论 -
Python 递归 list不正确
python 递归保存出来的list不正确1月16日厦门 OSC 源创会火热报名中,奖品多多哦 » ?1234567891011121314151617181转载 2016-01-03 21:28:44 · 715 阅读 · 0 评论 -
Division Operators
Division OperatorsIn general, the data type of an expresion depends on the types of the arguments. This rule meets our expectations for most operators: when we add two integers, the result should转载 2016-01-22 20:55:05 · 310 阅读 · 0 评论 -
Python Division and Remainders
1.4.1. Addition and SubtractionWe start with the integers and integer arithmetic, not because arithmetic is exciting, but because the symbolism should be mostly familiar. Of course arithmetic is imp转载 2016-01-12 21:25:48 · 523 阅读 · 0 评论 -
Python bitwise operator
bitwise 英 [bɪt'waɪz] 美 [bɪt'waɪz] n.逐位;按位However,you probably won't use the bitwise operators much.然而,也许不必过于频繁地进行按位运算。Is a numeric value representing the inclu转载 2016-01-22 23:40:44 · 1170 阅读 · 0 评论 -
None Python
What is the null or None KeywordThe null keyword is commonly used in many programming languages, such as Java, C++, C# and Javascript. It is a value that is assigned to a variable. Perhaps you h转载 2015-12-22 19:09:39 · 373 阅读 · 0 评论 -
Python Nested List Operation
1.列表就像数组:ist1=["I","love","python",2014]ist1['I', 'love', 'python', 2014] 列表的数据处理:假设你得到一组数据movies= ["The Holy Grail", 1975, "Terry Jones & Terry Gilliam", 91, [转载 2016-01-07 21:24:35 · 1449 阅读 · 0 评论 -
Python Binary Search
defbinarySearch( theValues, target ) :# Start with the entire sequence of elements.low = 0high = len(theValues) -1# Repeatedly subdivide the sequence in half until the target is found.wh转载 2016-01-07 23:45:00 · 1261 阅读 · 0 评论 -
Python List Pop
SyntaxFollowing is the syntax for pop() method −list.pop(obj=list[-1])Parametersobj -- This is an optional parameter, index of the object to be removed from the list.Return Val转载 2016-01-26 22:45:30 · 817 阅读 · 0 评论 -
An Introduction to Python Lists
An Introduction to Python ListsFredrik Lundh | August 2006Overview #The list type is a container that holds a number of other objects, in a given order. The list type implements the转载 2015-12-25 17:12:38 · 669 阅读 · 0 评论 -
Python Division //
In Python 3, they made the / operator do a floating-point division, and added the // operator to do integer division (i.e. quotient without remainder); whereas in Python 2, the / operator was si转载 2016-01-12 21:42:26 · 1103 阅读 · 0 评论 -
Delete Last Element
List method to delete last element in list as well as all elementsup vote13down votefavorite1yo folks, I have an issue with clearing lists. In the current转载 2016-03-01 21:56:11 · 437 阅读 · 0 评论 -
Python list reverse
Python List reverse() MethodAdvertisements Previous PageNext Page DescriptionThe method reverse() reverses objects of list in place.SyntaxFollowing is the sy转载 2016-03-01 21:58:50 · 346 阅读 · 0 评论 -
python queue
The Queue module has been renamed to queue in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.Source code: Lib/Queue.pyThe Queue转载 2016-03-02 10:10:32 · 532 阅读 · 0 评论 -
Python 线程同步
PYTHON和JAVA的线程同步的实现dbafree2012 年 08 月 14 日java, python发表评论 (0) 这篇文章本来只想写python的线程同步,不过因为之前有JAVA线程同步的经验,所以也温故知新下。个人mark下,很基础的知识,大牛绕过。文中部分知识点非原创。JAVA线程同步的实现:synchronized,wait(),n转载 2016-03-02 10:11:41 · 384 阅读 · 0 评论 -
python implement queue
用Python实现队列2012-12-14 1 个评论 作者:buaa_shang收藏 我要投稿[python] #!/usr/bin/env python queue = [] def enQ(): queue.append(raw_input('Enter new string: ').转载 2016-03-02 10:13:43 · 462 阅读 · 0 评论 -
Python - abs vs fabs
abs(-5)Secondimport mathmath.fabs(-5)How do these methods differ?pythonshareimprove this questionedited Feb 22 '14 at 16:46Paul Draper22.6k1156转载 2016-01-14 14:09:07 · 929 阅读 · 0 评论 -
Python chr ord
python chr()和ord() 标签: pythoncharacter2014-03-12 19:12 2103人阅读 评论(0) 收藏 举报 分类: python(4) 版权声明:本文为博主原创文章,未经博主允许不得转载。通过help 查看相关函数的帮助文档>>>help (chr)chr(...) ch转载 2016-02-14 19:31:35 · 383 阅读 · 0 评论 -
python sum
sum是python中一个很实用的函数,但是要注意它的使用,我第一次用的时候,就把它这样用了:s = sum(1,2,3)结果就悲剧啦其实sum()的参数是...sum是python中一个很实用的函数,但是要注意它的使用,我第一次用的时候,就把它这样用了:s = sum(1,2,3)结果就悲剧啦其实sum()的参数是一个list例如:sum([1,2,3])sum(转载 2016-03-17 10:11:03 · 1038 阅读 · 0 评论 -
Hash in Python
14.1. hashlib — Secure hashes and message digestsNew in version 2.5.Source code: Lib/hashlib.pyThis module implements a common interface to many different secure hash and message d转载 2016-03-05 11:50:33 · 618 阅读 · 0 评论 -
Python implement inverted index
一个倒排索引(inverted index)的python实现 标签: python索引搜索文档2016-02-01 22:35 26人阅读 评论(0) 收藏 举报 分类: python(1) 版权声明:本文为博主原创文章,未经博主允许不得转载。一个倒排索引(inverted index)的python实现使用sp转载 2016-03-18 11:38:47 · 593 阅读 · 0 评论 -
Python Static method vs class method
Static method vs class method in Python 标签: python2014-04-14 19:50 970人阅读 评论(0) 收藏 举报 分类: Python(6) Python中@static method和@class method对于刚接触的人而言,有很多迷茫的地方。随之,搜索了一些文章,然后整理如转载 2016-03-19 21:51:00 · 450 阅读 · 0 评论 -
Python 2.x vs 3.x
但如果想要用Python开发一个新项目,那么该如何选择Python版本呢?我可以负责任的说,大部分Python库都同时支持Python 2.7.x和3.x版本的,所以不论选择哪个版本都是可以的。但为了在使用Python时避开某些版本中一些常见的陷阱,或需要移植某个Python项目时,依然有必要了解一下Python两个常见版本之间的主要区别。目录使用__future__模块p转载 2016-03-20 14:19:53 · 341 阅读 · 0 评论 -
Python decorators example
Much of the discussion on comp.lang.python and the python-dev mailing list focuses on the use of decorators as a cleaner way to use the staticmethod() and classmethod() builtins. This capability is转载 2016-03-20 16:33:24 · 288 阅读 · 0 评论 -
Python Design Patterns
Design Patterns in PythonVespe SavikkoSoftware Systems Laboratory Tampere University of Technology FIN-33101 Tampere, Finland vespe@cs.tut.fiAbstractThe choice of implementation转载 2016-03-20 17:12:48 · 816 阅读 · 0 评论 -
Python singleton instantiation
Creational PatternsA creational pattern provides a particular instantiation mechanism. It can be aparticular object factory or even a class factory.This is an important pattern in compiled languag转载 2016-03-20 17:43:40 · 403 阅读 · 0 评论 -
Python class method
classmethod(function)Return a class method for function.A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method,转载 2016-03-20 17:50:31 · 440 阅读 · 0 评论 -
Python ord
ord(c)Given a string of length one, return an integer representing the Unicode code point of the character when the argument is a unicode object, or the value of the byte when the argument is an 8-b转载 2016-03-20 21:07:12 · 710 阅读 · 0 评论 -
Reverse traverse
1. range(N-1, -1, -1)2. reversed(range(N))3. range(N)[::-1]转载 2016-04-01 19:35:08 · 287 阅读 · 0 评论 -
Python queue
创建一个“队列”对象import Queuemyqueue = Queue.Queue(maxsize = 10)Queue.Queue类即是一个队列的同步实现。队列长度可为无限或者有限。可通过Queue的构造函数的可选参数maxsize来设定队列长度。如果maxsize小于1就表示队列长度无限。将一个值放入队列中myqueue.put(10)调用队列对转载 2016-04-02 21:33:46 · 324 阅读 · 0 评论 -
Python Thread
线程有五种状态新建、就绪、运行、阻塞、死亡。阻塞有三种情况: 同步阻塞是指处于竞争锁定的状态,线程请求锁定时将进入这个状态,一旦成功获得锁定又恢复到运行状态; 等待阻塞是指等待其他线程通知的状态,线程获得条件锁定后,调用“等待”将进入这个状态,一旦其他线程发出通知,线程将进入同步阻塞状态,再次竞争条件锁定; 而其他阻塞是指调用time.sleep()、anotherthre转载 2016-04-02 22:22:40 · 322 阅读 · 0 评论 -
Python multiprocessing threading
Python多线程/进程:os、sys、Queue、multiprocessing、threading当涉及到操作系统的时候,免不了要使用os模块,有时还要用到sys模块。设计到并行程序,一般开单独的进程,而不是线程,原因是python解释器的全局解释器锁GIL(global interpreter lock),本文最后会讲到。使用进程可以实现完全并行,无GIL的限制,可充转载 2016-04-02 23:10:09 · 824 阅读 · 0 评论 -
Python producer & consumer model
第六篇(五):生产者消费者模型实现多线程异步交互虽然标题是“生产者消费者模型实现多线程异步交互”,但这里要说的应该还包括Python的消息队列,因为这里多线程异步交互是通过Python的消息队列来实现的,因此主要内容如下: 1.生产者消费者模型:厨师做包子与顾客吃包子2.Python的消息队列3.利用消息队列实现Python多线程异步交互4.再谈耦合度的问题转载 2016-04-02 23:13:48 · 568 阅读 · 0 评论 -
python shlex
shlex模块实现了一个类来解析简单的类shell语法,可以用来编写领域特定的语言,或者解析加引号的字符串。 处理输入文本时有一个常见的问题,往往要把一个加引号的单词序列标识为一个实体。根据引号划分文本可能与预想的并不一样,特别是嵌套有多层引号时。 示例文本:Python1T转载 2016-04-03 21:45:56 · 7685 阅读 · 0 评论