python
文章平均质量分 65
matdodo
use knowledge to make the world better.
展开
-
Python3 分割二进制文件为小文件
Python作为脚本语言可以十分方便地编辑文件包括二进制文件。本文介绍了一种将大的二进制文件分割为多个小文件的案例代码。#Python3 分割二进制文件为小文件。原创 2023-08-23 15:54:23 · 299 阅读 · 0 评论 -
[flask]基础知识
Flask 基础知识基本框架结构from flask import Flaskfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmakerfrom database_setup import Base, Restaurant, MenuItemapp = Flask(__name__)engine = create_engine('sqlite:///restaurantmenu.db')Base.原创 2022-05-01 23:04:48 · 216 阅读 · 0 评论 -
[leetcode] Maximum Split of Positive Even Integers
Maximum Split of Positive Even IntegersYou are given an integerfinalSum. Split it into a sum of amaximumnumber ofuniquepositive even integers.For example, givenfinalSum = 12, the following splits arevalid(unique positive even integers sum...原创 2022-05-01 08:18:28 · 365 阅读 · 0 评论 -
web server using HTTPServer
build a web serverprotocolsTCP (transimission control protocol): 服务端将信息分成packages,通过网络与客户端进行传播。当一个包丢失后,服务端可以重新发送。UDP: User Datagram Protocol更适用于传输流媒体的信息(audio & video)DNS: domain name service. 用户输入www.baidu.com后,dns帮助转化网址为对应的ip地址。httpget 和 post原创 2022-04-30 23:58:27 · 1182 阅读 · 0 评论 -
simple cases about functional programming
import functoolsdef fac(n): return functools.reduce(lambda a,b:a*b, range(1,n+1))fac(5)120another solution is using operator moduleimport operatordef fact(n): return functools.reduce(opera原创 2015-10-30 15:57:51 · 639 阅读 · 0 评论 -
[DP] 后缀表达式与求值 visitor
none原创 2015-11-02 13:38:48 · 801 阅读 · 0 评论 -
[DP]strategy
none原创 2015-11-01 15:54:40 · 477 阅读 · 0 评论 -
[note] Iterator and Iterable
none原创 2015-12-21 16:39:03 · 750 阅读 · 0 评论 -
[note]how a generator works
none原创 2015-12-26 23:20:12 · 593 阅读 · 0 评论 -
[note]Linear Programming
none原创 2014-05-14 14:56:31 · 772 阅读 · 0 评论 -
inspect a function object
use inspect module to figure out the attributes in a function object. there is a clip function below:def clip(text, max_len=80): """ return text clipped at the last space before or after max_le原创 2015-10-30 15:56:24 · 936 阅读 · 0 评论 -
about dict
__missing__collections.ChainMapcollections.Countercollections.UserDicttypes.MappingProxyTypeUserDict->MutableMapping->Mapping原创 2015-10-28 16:04:01 · 766 阅读 · 0 评论 -
about hash
about __hash__hash表是一个稀疏数组或者说是一个总也填不满的数组。 在标准的数据结构的课本中,hash表中的一个单元叫bucket.在字典中,每个键值对都拥有一个bucket。 在这个bucket中,一部分存储对key(键)的引用,一部分存储对value(值)的引用。由于所有的bucket具有一样的空间。 所以,从一个bucket到另外一个bucket可以通过偏移量(offse原创 2015-10-28 22:17:53 · 478 阅读 · 0 评论 -
multithreading
转自: 廖学峰大神多线程一个进程至少有一个线程。 线程是操作系统直接支持的执行单元,因此,高级语言都支持多线程。 python的多线程是真正的posix thread,并不是模拟出来的线程。 原来,在标准库中有多线程模块,_thread以及threading。其中,_thread是低级模块,threadind是其封装版,比较高级。 使用高级模块不易出错,并且比较方便。import time转载 2015-09-24 17:32:25 · 673 阅读 · 0 评论 -
[note]构建常量
none原创 2015-09-20 14:40:27 · 516 阅读 · 0 评论 -
[笔记] lista += listb 与 lista = lista + listb
在一次编程中,错误的以为这两个方法的效果是相同的。细细想来才发现不对的地方, 以前都忽略掉了。 >>> g[12, 3, 4, 5, 9]>>> id(g)41829576L>>> g+=[0] # 相当于 append>>> id(g)41829576L>>> g = g + [9]>>> id(g)41853768L原创 2015-09-01 00:00:57 · 964 阅读 · 0 评论 -
[note]特殊方法
none原创 2015-10-18 23:18:13 · 485 阅读 · 0 评论 -
[note]CardDeck
none原创 2015-10-18 21:27:03 · 711 阅读 · 0 评论 -
python 2 编码问题
原作者:wuyou @newsmthPython2 的编码问题一直非常让人恼火,不过你的问题稍微简单一些。 在交互式命令模式(Interactive shell)下,可以这样来明白你遇到的问题的根源: >>> import sys >>> sys.stdout.encoding 在 Windows 下,如果你的系统是简体中文,一般输出会是 cp936 >>> impor转载 2015-09-06 13:32:32 · 675 阅读 · 0 评论 -
[note] Basic Information
none原创 2016-01-11 17:50:33 · 816 阅读 · 0 评论 -
[notes]chap14 Iterator Generator-expression 生成器表达式
generator-expression生成器表达式the differences between list comprehension and generator expressiondef gen_AB(): print("start") yield 'A' print("continue") yield 'B' print("end.")res1 = [原创 2016-03-15 20:10:23 · 601 阅读 · 0 评论 -
sequence alignment
# this problem is also called 'edit distance'# consider sequence X = (x1,x2,..,xm) and Y=(y1,y2, ..., yn);# an alignment is a subset A belongs to {1,...,m} * {1, .., n}# for any (i,j) and (i',j'原创 2017-10-20 06:01:48 · 1618 阅读 · 0 评论 -
wrapping a C library with cython
an example to show how to wrap c code for python with cython原创 2017-07-09 12:51:56 · 431 阅读 · 0 评论 -
cffi: 连接python与C的桥梁
想在python中无痛地调用C语言吗?快用cffi吧!下面我给大家演示一下,python是如何通过cffi调用c程序的。首先,我自己写了个三维向量结构体:Vec3.具体分为两个文件: vect3.h 和 vect3.c.vect3.h如下:#define HELLO 3typedef struct{ double x; double原创 2017-04-01 20:54:26 · 9139 阅读 · 2 评论 -
Python中子类如何获取父类的类成员
@bwangel 大家好,今天在写代码的时候,遇到了这样一种情况。我有如下所示的几个类用来存放程序配置(其实当做命名空间来用,同时感觉能够继承方便一点),import osclass Config: BASE_DIR = "/tmp"class TestConfig(Config): DATA_DIR = os.path.join(Config.BASE_DIR,转载 2017-03-07 00:12:32 · 12017 阅读 · 0 评论 -
[CompStat][计算统计][0]sharpen your tools
IPython (交互式python命令行工具)是一种增强型python shell软件。 它给用户提供了更具鲁棒性和效率性的开发环境。其中,它的几个关键特性与标准python shell不同。命令历史ipython中,你所有的输入输出都会被保存(这比标准python shell高级多了)。它提供了两个变量In和Out分别存储你的输入输出。 所有输出自动保存到变量_N 其中N为输出cell的序号。原创 2016-12-22 17:01:10 · 992 阅读 · 0 评论 -
[visualization]nextworkx_example - graphic data visualization
利用networkx创建图数据,并进行可视化的例子。原创 2016-12-10 01:38:39 · 1014 阅读 · 0 评论 -
examples - visualizing time series data and geographic data using python
利用cartopy和pandas处理时间序列数据和地理数据。pandas中介绍了处理日期的函数pandas.to_datetime, groupby 的使用。cartopy初步介绍了画地理信息图的方法。地理信息GIS专业的同学可能用到。原创 2016-12-09 16:08:03 · 1646 阅读 · 2 评论 -
[pySpark][note]Click-Through Rate Prediction
Click-Through Rate Prediction LabThis lab covers the steps for creating a click-through rate (CTR) prediction pipeline. You will work with the Criteo Labs dataset that was used for a recent Kaggle com原创 2016-09-08 20:24:07 · 2904 阅读 · 0 评论 -
[pySpark][note]Linear Regression
Linear Regression LabThis lab covers a common supervised learning pipeline, using a subset of the Million Song Dataset from the UCI Machine Learning Repository. Our goal is to train a linear regression原创 2016-09-08 20:10:50 · 2738 阅读 · 0 评论 -
[pySpark][note]Text Analysis and Entity Resolution
+ Text Analysis and Entity ResolutionEntity resolution is a common, yet difficult problem in data cleaning and integration. This lab will demonstrate how we can use Apache Spark to apply powerful and s原创 2016-09-07 20:59:31 · 5641 阅读 · 0 评论 -
[pySpark][note]Word Count Lab: Building a word count application
+ Word Count Lab: Building a word count applicationThis lab will build on the techniques covered in the Spark tutorial to develop a simple word count application. The volume of unstructured text in ex原创 2016-09-07 20:34:19 · 2172 阅读 · 1 评论 -
[pySpark][note]Web Server Log Analysis with Apache Spark
version 1.0.1 + Web Server Log Analysis with Apache SparkThis lab will demonstrate how easy it is to perform web server log analysis with Apache Spark.Server log analysis is an ideal use case for Spark原创 2016-09-07 20:46:45 · 8802 阅读 · 0 评论 -
HangMan 猜单词 一个简易的吊死鬼游戏 python版
一个很简单的猜单词游戏。你的机会是有限的,你每猜错一次,你要拯救的小人就出现一部分。当整个小人出现的时候,游戏结束,你便看到了惨象:一个吊死的屌丝!可以把单词换成你每天背的单词,便于复习。。。直接放代码。#!usr/bin/env python#-*- coding:utf-8 -*-import randomtry: impor原创 2016-03-22 01:30:00 · 10234 阅读 · 0 评论 -
[笔记]python multiprocessing模块
现在越来越多的计算机程序采用多进程,多线程。C++, Java都提供了多进程多线程模块,python也不例外。python在多进程方面提供了multiprocessing模块。原创 2015-07-23 19:40:02 · 3547 阅读 · 0 评论 -
[notes]Iterator-1:Sentence class Python迭代器基本概念
Iterator Iterable原创 2016-03-02 23:28:03 · 869 阅读 · 0 评论 -
[笔记]遗传算法 genetic algorithm
引言遗传算法是最优化问题的常用方法,尤其是组合优化,常常可以得到近似最优解。从物种的进化历史来看,物种的进化正是自我优化的过程。从种群上来看,进化这一过程中,目标函数正是物种对环境的适应能力,限制条件就是严酷的自然环境,而状态表征量正是物种的遗传物质,基因,DNA,RNA等。假设环境不变的话,每一代物种都比上一代物种更加适应这个环境,因为不能适应环境的基因已经被淘汰。这一代代的淘汰与繁衍,正是一代代原创 2015-08-04 19:42:08 · 2010 阅读 · 1 评论 -
[笔记]numpy中的tile与kron的用法
numpy中提供了不少数学中矩阵的运算、构造函数。闭上眼睛想一想,发现其中常用的也就是那么几个:cos, sin, mean, dot, max,min, outer,argsort,ones,zeros,arrange,reshape,fft………等。想了半天,可以也不超过30个左右常用函数。但是numpy的确博大精深:查看文档发现有大概586个方法或属性!今天,我就记录一下numpy中,矩阵运原创 2015-07-23 23:47:14 · 9448 阅读 · 0 评论 -
[debug] debugging in python with pdb
Debugging in PythonPosted on 2009/09/10 by Steve FergAs a programmer, one of the first things that you need for serious program development is a debugger.Python has a debugger, which is available as a转载 2015-07-28 16:28:10 · 1036 阅读 · 0 评论 -
[leetcode] Remove Duplicates from Sorted Array python
leetcodeGiven a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must d原创 2014-05-17 22:14:16 · 877 阅读 · 0 评论