强弱类型到底是个啥?
程序员们喜欢撕逼,他们会争论vim和emacs那个才是最牛逼的编辑器,会比较linux和windows哪个更牛逼些,还会比较java和c#哪个更强大一些,因为他们总喜欢追寻自己的教条和信仰,跟别的队伍吵个不停。最近总听见有人在讨论关于编程语言的强弱类型,他们常常为某种语言是不是弱类型吵得不可开交。jser,phper们可能是因为被黑惯了,他们一般表现出”你说啥都行,弱类型就弱类型,无所谓,你们开心就...
View ArticlePython内置函数(64)――tuple
英文文档: The constructor builds a tuple whose items are the same and in the same order as iterable ‘s items. iterable may be either a sequence, a container that supports iteration, or an iterator object....
View ArticlePython最差实践
最近在看一些陈年老系统,其中有一些不好的代码习惯遗留下来的坑;加上最近自己也写了一段烂代码导致服务器负载飙升,所以就趁此机会总结下我看到过/写过的自认为不好的python代码习惯,时刻提醒自己远离这些“最差实践”,避免挖坑。 下面所举的例子中,有一部分会造成性能问题,有一部分会导致隐藏bug,或日后维护、重构困难,还有一部分纯粹是我认为不够pythonic。所以大家自行甄别,取精去糟吧。...
View ArticlePython 机器学习算法入门之梯度下降法实现线性回归
\ k ZZR ,python中文社区专栏作者,OpenStack工程师,曾经的NLP研究者。主要兴趣方向:OpenStack、Python爬虫、Python数据分析。 Blog: http://skydream.me/ CSDN: http://blog.csdn.net/titan0427/article/details/50365480 ― ― 1. 背景 文章的背景取自 An...
View ArticlePyQt5如何实现对QTreeWidget下所有Item的遍历
前言:作为一只菜鸟,无法像诸位大神那样在描述问题之前深入浅出地介绍背景TAT,只能默认来看这篇文章的人对QTreeWidget已经有过了解,想在python中实现对其下所有Item的遍历。 由于试手的软件里需要实现按下相关功能键后,删除 QTreeWidget 中打勾(即checked)的item。所以需要遍历所有item检查状态。在阅读QT文档的时候(因为PyQt5的Reference...
View ArticleOCR识别验证码
最近在爬某网站,老是蹦出来验证码,就想着找个OCR破了这个验证码,然后就开始了OCR探索之旅。 首先简单说一下什么是OCR OCR是(Optical Character Recognition, 光学字符识别 )的简称,主要用途: 办公用途,用来识别图片里面的文字,可以高效率的录入图片类型文件。 识别网站验证码 详见 维基百科 或者 百度百科 OCR识别的验证码原理...
View ArticleThe Best New Feature in unittest You Didn’t Know You Need
From time to time I like to read documentation of modules I think I know well. The python documentation is not a pleasant read but sometimes you strike a gem. Same thing but slightly different...
View ArticleOn the Proper Care and Feeding of REST APIs, Part II
In the first part of this article we introduced the choice of tools used to build our API. In this second part I’ll go into the details of how we used these tools, what challenges we faced, and how we...
View ArticleAlbert Hopkins: Packaging static Sphinx-based documentation in a reusable...
At my job we have a few Django apps which are packaged as reusable Django apps . Some of those apps have documentation generated by Sphinx that need to be served along with the served app (as opposed...
View ArticlePython内置函数(65)――type
英文文档: class type ( object ) class type ( name , bases , dict ) With one argument, return the type of an object . The return value is a type object and generally the same object as returned by....
View ArticlePython内置函数(66)――vars
英文文档: vars ( [ object ] ) Return theattribute for a module, class, instance, or any other object with a __dict__ attribute. Objects such as modules and instances have an updateable __dict__ attribute;...
View Article总结:Python中的异常处理
异常处理在任何一门编程语言里都是值得关注的一个话题,良好的异常处理可以让你的程序更加健壮,清晰的错误信息更能帮助你快速修复问题。在python中,和不部分高级语言一样,使用了try/except/finally语句块来处理异常,如果你有其他编程语言的经验,实践起来并不难。 处理异常 try…excpet…finally 实例代码 try: print 2/'0' except...
View ArticleExperienced Django: Exploring with Cookiecutter
After reading Two Scoops of Django, I decided to explore the cookiecutter app that they recommend. If you haven’t used it, cookiecutter is ” A command-line utility that creates projects from...
View Articlefunctools
functools 模块包含了非常多很有用的函数,甚至可以说是比较常用的。这些函数主要用于创建高阶函数、函数式编程和装饰器的函数和装饰器。 partial() def spam(a,b,c,d): print(a,b,c,d) from functools import partial s1 = partial(spam,1) s1(2,3,4) # 1,2,3,4 在类定义中使用partial,...
View Articlepython:切片字符
python的切片字符:(:) 1、单切片字符 python的切片字符用于元组、字符串或者列表,采用的是左闭右开,即包含冒号左侧的第N个个数,不包含右侧的数,下面以列表示例: >>> a=[1,2,3,4] >>> a[1:] [2, 3, 4] >>> a[1:3] [2, 3] >>> a[:3] [1, 2, 3]...
View ArticlePython Tutorial - Starting Your Cookbook
Links python - http://www.python.org/download PyCharm - http://www.jetbrains.com/pycharm GitHub - https://github.com Git for windows - https://git-scm.com/download/win The Cookbook Method -...
View ArticlePython内置函数(67)――zip
英文文档: zip ( *iterables ) Make an iterator that aggregates elements from each of the iterables. Returns an iterator of tuples, where the i -th tuple contains the i -th element from each of the argument...
View Articlepython中的argparse
argparse是python用于解析命令行参数和选项的标准模块,用于代替已经过时的optparse模块。argparse模块的作用是用于解析命令行参数。 最基础的,从一个最简单的程序开始: import argparse parser = argparse.ArgumentParser() 运行结果: $ python 1.py $ 定位参数: import argparse...
View ArticlePython函数式编程:从入门到走火入魔
很多人都在谈论函数式编程(Functional Programming),只是很多人站在不同的角度看到的是完全不一样的风景。坚持实用主义的 python 老司机们对待 FP 的态度应该更加包容,虽然他们不相信银弹,但冥冥中似乎能感觉到 FP 暗合了 Python 教义(The Zen of Python)的某些思想,而且既然 Python...
View ArticleLintel Technologies: Asynchronous HTTP Responses using twisted.web
In Twisted web, Resources may generate it’s response asynchronously rather than immediately upon the call to its render method. This is different from other synchronous python frameworks like django,...
View Article