Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Browsing all 9596 articles
Browse latest View live

Python进制转换

python中的进制转换十分方便,使用int(object[, radix])函数 作用:将字符串或者数字(可以提供基数)转换为整数 全局定义 base = [str(x) for x in range(10)] + [ chr(x) for x in range(ord('A'),ord('A')+6)] 二进制 to 十进制: int(str,n=10) int(string_num, 2)...

View Article


Updates from PyCon Pune, 12th January

This is a small post about PyCon Pune 2017 . We had our weekly volunteers meet on 12th January in the hackerspace . You can view all the open items in the GitHub issue tracker . I am writing down the...

View Article


Python print报ascii编码异常的靠谱解决办法

之前遇到此异常UnicodeEncodeError: 'ascii' codec can't encode characters...,都是用这种方式解决:sys.setdefaultencoding('utf-8') 今天看到如下文章,阐述了此方式的弊端: http://blog.ernest.me/post/python-setdefaultencoding-unicode-bytes...

View Article

Python标准库之functools/itertools/operator

本文为作者原创,转载请先与作者联系。 同发于 SegmentFault 和 简书 引言 functools , itertools , operator 是python标准库为我们提供的支持函数式编程的三大模块,合理的使用这三个模块,我们可以写出更加简洁可读的Pythonic代码,接下来我们通过一些example来了解三大模块的使用。 functools的使用 partial...

View Article

python基础4

内容概要: 一、递归 递归就是函数本身调用自己,直到满足指定条件之后一层层退出函数 递归特性: 必须有一个明确的结束条件 每次进入更深一层递归时,问题规模相比上次递归都应有所减少...

View Article


从python到java设计模式之抽象工厂模式

之前的博客提到过设计模式的主要思路就是直接通过接口(实现接口),或者间接通过接口(中间对象)来进行解耦的,并介绍了两种行为型设计模式,命令模式和策略模式,这次介绍一个来自创建型模式的抽象工厂模式。 简单工厂 其实在创建型模式中,有一种常常被用来举例,却没有归类到真正的设计模式中,就是简单工厂模式。 比如如下创建对象的方式,让创建对象的方式变得耦合。 Pencil pencil = new...

View Article

Image may be NSFW.
Clik here to view.

python 学习笔记 - Queue & Pipes,进程间通讯

上面写了python如何创建多个进程,但是前面文章中创建的进程都是哑巴和聋子,自己顾自己执行,不会相互交流。 那么如何让进程间相互说说话呢? Python为我们提供了一个函数multiprocessing.Pipe 和一个类:multiprocessing.Queue。 multiprocessing.Pipe() multiprocessing.Pipe()...

View Article

Image may be NSFW.
Clik here to view.

Generating Icons with Pixel Sorting

Created on Jan. 14, 2017, 12:27 p.m. Many sites these days provide randomly generated images for avatars if the user hasn't uploaded their own image. For example Github provides identicons which are...

View Article


Image may be NSFW.
Clik here to view.

Python二维列表获取子区域元素组成

python二维列表获取子区域元素组成 2017.01.14 21:34:06 用过NumPY的应该都知道,在二维数组中可以方便地使用区域切片功能,如下图: 而这个功能在Python标准库的List中是不支持的,在List中只能以一维方式来进行切片操作: 但有时候我只想用一下这个功能,但又不想引入NumPY。其实这时候我也是可以在Python中实现的。这时候,只需在一个类中实现...

View Article


Me: 2016 retrospective

My 2016 retrospective in which I talk about projects I worked on, pushed off and other things. I spent some time in 2016 passing one of my big projects off: PyVideo : In January 2016, I announced I was...

View Article

A Python interface to AO3 →

ao3.py This python package provides a scripted interface to some of the data on AO3 (the Archive of Our Own). It is not an official API. Motivation I want to be able to write Python scripts that use...

View Article

if as syntax possibility

I have a small niggle that comes up in my python programming. I'm going to describe it and propose a possible addition to the Python programming language that would mostly solve the problem. However, I...

View Article

Image may be NSFW.
Clik here to view.

ElasticSearch with Django the easy way

A while back I was working on a Django project and wanted to implement fast free text search. Instead of using a regular database for this search function ― such as mysql or PostgreSQL ― I decided to...

View Article


elike.python.function()

将python用于基本的科学计算,能完全替代matlab。就最近写的一个物理模型程序来看,用python建立的物理模型的可控性,代码的层次性都优于matlab,只不过python没有matlab那样的界面,所有的操作都需要代码来实现。现关于python的函数式编程做出以下总结。 问题一:物理公式里有很多的小公式,一个一个的def太麻烦了,有什么好的解决办法?...

View Article

Image may be NSFW.
Clik here to view.

Trap in counting related objects in Django

Task: for every object count number of related objects satisfying some conditions. Example: class Category(models.Model): title = models.CharField(max_length=50) class Article(models.Model): title =...

View Article


Image may be NSFW.
Clik here to view.

Python科学计算之Pandas

起步 Pandas 是 python 的一个数据分析包,属于PyData项目的一部分。Pandas最初被作为金融数据分析工具而开发出来,因此 pandas 为时间序列分析提供了很好的支持。 Pandas 的名称来自于面板数据(panel data)和python数据分析 (data analysis) 。panel...

View Article

Python 奇技淫巧 (一)

文章中的代码仅在python3中测试成功,没有在Python2中测试。 0X00 *表达式 从某个可迭代对象中分解出N个元素,但是这个可迭代的对象可能会超过N,会出现too many values to unpack异常。 比如我这儿有N个统计信息,因为第一次和最后一次的信息不准确需要删除掉,而将中间的信息保留下来,那么就可以这么弄。 #!/usr/bin/python #...

View Article


Python的super函数是否需要参数

作者:杨冬 欢迎转载,也请保留这段声明。谢谢! 出处: https://andyyoung01.github.io/ 或 http://andyyoung01.16mb.com/...

View Article

python2.7转golang

Grumpy 是一个实验性的 python 运行时。它将 Python 代码翻译成 Go 程序,转译(transpiled)得到的程序可以与 Go 运行时无缝集成。 Grumpy 去掉了 GIL,这就可以利用 Go 的垃圾收集来管理对象生命周期,而不再是依赖引用计数.,Grumpy 可以分为 grumpc 、 Grump 运行时和 Grumpy 标准库三块。其中grumpc 负责将 Python...

View Article

修改 Flask 的默认响应头实现跨域(CORS)支持

本站文章除注明转载外,均为本站原创或者翻译。 本站文章欢迎各种形式的转载,但请18岁以上的转载者注明文章出处,尊重我的劳动,也尊重你的智商; 本站部分原创和翻译文章提供markdown格式源码,欢迎使用 文章源码 进行转载; 本博客采用WPCMD 维护; 本文标题:修改 Flask 的默认响应头实现跨域(CORS)支持 本文链接: http://zengrong.net/post/2615.htm...

View Article
Browsing all 9596 articles
Browse latest View live