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

Factory pattern in python

What is factory pattern all about? It introduces abstraction. In other words: helps software developers with the problem of creating objects without knowing exact class of the object that will be...

View Article


Image may be NSFW.
Clik here to view.

[原] 深入对比数据科学工具箱:Python 和 R 的异常处理机制

概述...

View Article


python之路―――第一章

初识python #以下的代码都是在PyCharm 4.5的编辑工具下执行的,并且python的版本是3.4 python的第一程序 print("Hello Word") #Hello Word 一、变量名 一) 作用:一是用来存储,二是用来调用 二)定义规则: 1)变量名只能是字母、数字、下划线的任意组合 2)变量名的第一字母不能是数字或下划线 3)关键字不能声明变量 比如:if、 for、...

View Article

Vasudev Ram: How to kill yourself in Python

By Vasudev Ram Here's a simple python program that shows how the os.kill function from Python's standard library, along with the os.getpid function and the signal module [1], can be used to terminate...

View Article

Image may be NSFW.
Clik here to view.

Pure Python: Loading Shapefiles into PostGIS

In addition to being the best spatial database engine available, PostGIS can be manipulated using pure python without any C-library dependencies. PostGIS is the spatial database engine for the open...

View Article


Image may be NSFW.
Clik here to view.

python blinker 库学习

python blinker 库学习 一点号数据玩家昨天 限时干货下载: 回复【2】免费获取【超全数据分析资料免费下载(包含SQL,R语言,SPSS,SAS,python,数据挖掘)!】 来源:segmentfault.com/a/1190000005814855 作者:fireflow Blinker...

View Article

Image may be NSFW.
Clik here to view.

[工具资源] 一个更好的 Python 交互解释器

ptpython A better Python REPL pip install ptpython Ptpython is an advanced Python REPL. It should work on all Python versions from 2.6 up to 3.5 and work cross platform (linux, BSD, OS X and windows)....

View Article

Image may be NSFW.
Clik here to view.

Python&web编程

这里的web编程不是指用python开发web程序,而是指用python与web交互,获取web信息。无论哪一种语言,与web进行交互,都是hack必不可少的技能。 嗯,这节课包括三部分,我会尽量写的有趣一点,以便大家能够欢乐的看完这篇笔记。 01 urllib,urllib2,requests 举个栗子,首先进入py环境。 [Python] 纯文本查看 复制代码 import...

View Article


Dictionary Methods in Python | Set 1 (cmp(), len(), items()…)

python Dictionary Basics have been discussed in the article below Dictionary Some dictionary methods are discussed in this article. 1. str(dic):- This method is used to return the string , denoting all...

View Article


Image may be NSFW.
Clik here to view.

利用 Python 进行数据分析(九)pandas 汇总统计和计算

pandas 对象拥有一些常用的数学和统计方法。 例如,sum() 方法,进行列小计: sum() 方法传入 axis=1 指定为横向汇总,即行小计: idxmax() 获取最大值对应的索引: 还有一种汇总是累计型的,cumsum(),比较它和 sum() 的区别: unique() 方法用于返回数据里的唯一值: value_counts() 方法用于统计各值出现的频率: isin()...

View Article

Image may be NSFW.
Clik here to view.

Python黑帽编程2.4 流程控制

python 黑帽编程 2.4 流程控制 本节要介绍的是 Python 编程中和流程控制有关的关键字和相关内容。 2.4.1 if …..else 先上一段代码: #!/usr/bin/python # -*- coding: UTF-8 -*- x=int(input(' 请输入一个整数 :')) if x==0: print '%d ==0' % x elif x<0: print...

View Article

使用Python转换全角字符串为半角

Aug 07, 2016 关于全角转换为半角的问题,其实源自在公司的运营人员在输入法切换的时候选择了全角,结果导致程序有时候没有办法进行解析。 为了避免这样的问题再次出现,于是就有了将全角转换为半角的问题了。 在这里,会对以下内容进行描述: 什么是全角 如何将全角字符转换为半角 使用python实现上述转换操作...

View Article

Image may be NSFW.
Clik here to view.

用python爬虫抓站的一些技巧总结

1.最基本的抓站 import urllib2 content = urllib2.urlopen('http://XXXX').read() 2.使用代理服务器 这在某些情况下比较有用,比如IP被封了,或者比如IP访问的次数受到限制等等。 import urllib2 proxy_support =...

View Article


Dictionary Methods in Python | Set 2 (update(), has_key(), fromkeys()…)

Some of the Dictionary methods are discussed in set 1 below Dictionary Methods in python | Set 1 (cmp(), len(), items()…) More methods are discussed in this article. 1. fromkeys(seq,value):- This...

View Article

python 分片、截断列表

介绍 这篇文章主要介绍python对“列表”的分片方法。通过分片规则可以很简单的处理一些复杂的for循环操作。 “列表”概念 注意这里的“列表“指的不是前面讲的list,这里所讲的列表是一个统称的概念,在分片规则里list、tuple、str(字符串)都可以当做列表,都可以按规则进行切片操作 切片操作...

View Article


map 与 for 的性能对比

预备知识:python 对变量搜索是用的是环境模型,顺序是 Local - Enclosing - Global - Builtin,记不住的就记 LEGB (一句脏话)。简单点说就是在当前环境搜变量/方法,如果没有,就去上一环境搜,搜到 builtin 都没有,就会报错。 这段我主要对比 map 跟 for 循环。我们来看看 map 跟 for 的字节码都干了什么,...

View Article

Image may be NSFW.
Clik here to view.

PyDev of the Week: Ben Nuttall

This week we welcome Ben Nuttall ( @ben_nuttall ) as our PyDev of the Week. Ben is a Raspberry Pi Community Manager http://bennuttall.com/ and is the creator of GPIO Zero , which is a simple interface...

View Article


Image may be NSFW.
Clik here to view.

Python 学习:urllib 简介

python 学习:urllib 简介 昨天来源:linux中国 Python 3 的 urllib 模块是一堆可以处理 URL 的组件集合。如果你有 Python 2 的知识,那么你就会注意到 Python 2 中有 urllib 和 urllib2 两个版本的模块。这些现在都是 Python 3 的 urllib 包的一部分。当前版本的 urllib 包括下面几部分:...

View Article

Image may be NSFW.
Clik here to view.

用惨痛的经历告诉你Python奇葩语法:代码缩进不是为了排版

用惨痛的经历告诉你python奇葩语法:代码缩进不是为了排版 2天前来源:CPP程序员 [摘要]鉴于没有全面学习Python语法,就直接使用Python语言编程,被Python的潜规则给狠狠的打了一巴掌。不过,最后发现问题,也是一番探索得来,虽然辛苦,但是也很快乐。Python的缩进并不是为了排版哦。 今天要来说一下Python的一个语法规定,那就是代码缩进。今天被这个坑了一阵子,所以来说说经过。...

View Article

Django REST framework简单使用

详细的见https://github.com/linux-wang/DRF_tutorial/blob/master/README.md DRF中有一个serializer的概念,实现的功能是将各种Django Queryset和model instance转换成python原生格式,这里就省去了你自己写API的时候面临的类型问题,当然也可以逆向操作。官方文档如下: Serializers...

View Article
Browsing all 9596 articles
Browse latest View live