Django的F()表达式
算是一些基本的高级用法吧,在Django文档的 Query-related classes 这一章中。主要讲了三个类, F() , Q() 和 prefetch() 。我们下面讲一讲 F() 。 class F() F()是代表模型字段的值,也就是说对于一些特殊的字段的操作,我们不需要用python把数据先取到内存中,然后操作,在存储到db中了。 ##常见的使用场景 ###字段加1(加减乘除运算)...
View ArticleDjango Interview
##Django的Model的继承有几种形式,分别是什么? ###抽象继承: 顺便复习OOP思想,继承是面向对象的大前提。抽象类之所以被创建是用来被继承的;一个类如果包含任何一种抽象方法,那么它就是抽象类;抽象方法一定要在子类中被复写;在继承关系中,抽象类永远在树枝节点上,而且对于python来说,已经没有这么多约束了。 回到Django的 Model...
View Articlesqlalchemy学习笔记
SQLAlchemy 是python的一个数据库ORM工具,提供了强大的对象模型间的转换,可以满足绝大多数数据库操作的需求,并且支持多种数据库引擎(sqlite,mysql,postgres, mongodb等),在这里记录基本用法和学习笔记 一、安装 通过pip安装 $ pip install SQLAlchemy 二、使用...
View ArticleFederico Campoli: Mighty morphin power elephant
Back in the 2013 I started playing with sqlalchemy to create a simple extractor from heterogeneous systems to be pushed in postgresql. I decided to give the project a name which recalled the...
View ArticlePython检测服务端口存活状态并报警
最近发现公司的测试环境中有个Socket服务的端口总是莫名其妙Down掉,但是服务却正常运行着,看样子是僵死了。。。 虽然是测试环境,但是也不能这样放着不管,于是连夜写了一个简单的监控脚本。因为服务器是windows的,所以要用到wmi模块。逻辑如下: 1、用wmi模块获取系统中处于停止状态的服务,生成一个字典。...
View ArticlePython-Day9 Paramiko模块/进程/线程/RabbitMQ队列
一、Paramiko模块 1.Paramiko安装 python的目录下有个Scripts目录,cd到这个目录用这里面的pip命令(如果添加的环境变量可以在cmd直接输入命令):pip install paramiko。如果pip版本低会有提示,python -m pip install --upgrade pip 升级pip,再次输入pip install paramiko。...
View ArticleQuine in Python
Quine is a program which takes no input but outputs a copy of its own code. We have discussedquine in C. The shortest possible quine in python is just a single line of code! _='_=%r;print _%%_';print...
View ArticleWriting Redis in Python with asyncio 2: Shared State
I've been writing redis in python using asyncio. I started this project because I wanted to learn more about asyncio and thought that porting an existing project to asyncio would give me an excellent...
View ArticleRuby vs Python, the Definitive FAQ
“python or Ruby” is the one of the most hotly debated topics in the programming world, ranking just behind “emacs or vim” and “pro-skub or anti-skub” in importance and complexity. This FAQ will...
View ArticlePython 编写 Github Webhook
这篇博文可以让你明白,什么是 Webhook ,Webhook有哪些事件,设置Webhook的条件和流程。特别是自动部署线上服务器。和一些简单的linux操作。今年五月份的时候,因为毕业设计是做一个app,所以需要写后端,那个时候只懂用 Java EE 做后端。所以就用Java...
View Article使用Python创建LDA模型进行分类
线性判别式分析(Linear Discriminant Analysis)简称LDA,是模式识别的经典算法。通过对历史数据进行投影,以保证投影后同一类别的数据尽量靠近,不同类别的数据尽量分开。并生成线性判别模型对新生成的数据进行分离和预测。本篇文章使用机器学习库scikit-learn建立LDA模型,并通过绘图展示LDA的分类结果。 准备工作...
View ArticleWhat was I thinking?
Check out this idiocy: https://github.com/slott56/py-false What is the point? Seriously. What. The. Actual. Heck? I think of it this way. Languages are a cool thing. Especially programming languages...
View ArticleWeeklyBlog 第三期
由于一些原因第三期的文章姗姗来迟,这里表示抱歉。这期加入了新成员,也带来了新的文章。 python Python 生成器和协程那点事儿 ( @写代码的香港记者 ) 本来想这周继续写写 Flask 那点破事儿的,但是想了想决定换换口味,来聊聊很不容易理解但是很重要的 Python 中的生成器和协程。 Java 知识点 Java 注解 (Annotation) ( @Win_Man )...
View ArticleCaching in Django with Redis
Application performance is vital to the success of your product. In an environment where users expect website response times of less than a second , the consequences of a slow application can be...
View Article使用Python写CUDA程序
使用python写CUDA程序有两种方式: numba PyCUDA numbapro 现在已经不推荐使用了,功能被拆分并分别被集成到 accelerate 和Numba了。 例子 numba...
View ArticleDjango-优化数据库查询
##一次检索你需要的所有东西 在不同的位置多次访问数据库,一次获取一个数据集,通常来说不如在一次查询中获取它们更高效。如果你在一个循环中执行查询,这尤其重要。有可能你会做很多次数据库查询,但只需要一次就够了。 我们需要充分了解并使用 select_related() 和 prefetch_related() ###select_related() Returns a QuerySet that...
View ArticleProductive Python with PyCharm tutorial materials from PyCon India 2016
September 23th 25th, the JetBrains PyCharm Team will be in New Delhi, India for PyCon India 2016 . As an important part of our participation, we’re going to conduct a 3-hours Productive Coding with...
View Article程序生成word与PDF文档的方法(python)
程序生成word与PDF文档的方法(python) 一点号小窗科技3小时前 程序导出word文档的方法将web/html内容导出为world文档,再java中有很多解决方案,比如使用Jacob、Apache...
View ArticleCounting words in HathiTrust with Python and MPI
[Cross-posted from the Stanford Literary Lab’s Techne blog] In recent months we’ve been working on a couple of projects here in the Lab that are making use of the Extracted Features data set from...
View ArticleTuples
There are quite a few good responses to these tweets, both from David and from others (and from yours truly). I recommend reading the the thread (click on the first tweet above). Now to start off, I...
View Article