Python
共 12 篇文章
Python 国际化
>>> help(locale) Help on module locale: NAME locale - Locale support. FILE c:\python27\lib\locale.py DESCRIPTION The module provides low-level access to the C lib's locale APIs and adds high level number formatting APIs as well as a locale aliasing engine to complement these. The aliasing engine in…
2011-09-18 11:14 · Python
python 的一些常用方法
1.生成随机数 02 import random #这个是注释,引入模块 03 rnd = random.randint(1,500)#生成1-500之间的随机数 04 05 2.读文件 06 07 f = open("c:\\1.txt","r") 08 lines = f.readlines()#读取全部内容 09 for line in lines 10 print line 11 3.写文件 12 f = open("c:\\1.txt","r+")#可读可写模式 13 f.write("123")#写入字符串 14 15 4.正则表达式,读取tomcat的日志并打印日期 16 17…
2011-09-11 00:17 · Python
python 日期时间常用操作
关于python时间模块问题 #:当前时间时间戳 1312181113.31 print(time.time()) #将字符串转成时间戳 ts = '2011-08-01 14:15:40' b = time.mktime(time.strptime(ts,'%Y-%m-%d %H:%M:%S')) print(b) #返回指定时间的时间戳使用mktime d = datetime.datetime(1997,12,29,15,59,59) t = d.timetuple()#再转为元组 print(time.mktime(t)) #使用time的mktime方法返回时间戳 #将时间戳转成时…
2011-09-11 00:14 · Python
老王带给你免费的python教程
亲爱的朋友: 欢迎你!很高兴能在这里见到你,你能来到这里说明你真的很喜欢python,很想把python给学好!我觉的你很幸运,开始我学python的时候比较少资料,学起来也比较头疼,现在随着python越来越流行, 资料也越来越多,大家以后学起来应该会轻松很多了。我前段时间花了很多时间整理了一些python教程,我觉的对初学python的朋友来说是个很好的引路人,我相信通过它你可以快速的上手python的。不信可以试试哦! 最近索取资料的朋友比较多,让老王python感到欣慰!为了让更多的朋友了解python,学习python,喜欢python! 我做出了一个艰难的决定:如果你想要得到这份…
2011-08-17 19:32 · Python
使用CMD模块,让脚本更舒服些
转自: 蛇小狼 平时由于经常给测试人员调试一些东西,虽然写了一些脚本,感觉还是不方便。 python的cmd模块提供的更优雅的方式,很喜欢。 刚写了一些平时常用的测试代码: # -*- coding:utf-8 -*- import os, sys from datetime import datetime import cmd import warnings from django.conf import settings def not_exit(func): def _func(*args, **kwargs): try: res = func(*args, **kwargs) ret…
2011-08-07 10:46 · Python
回显流服务器
TCP: 服务器: # _*_ coding: utf-8 _*_ import socket srvsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) srvsock.bind(('', 23000)) srvsock.listen(5) while 1: # 循环处理各个客户机连接 # 调用accept方法并阻塞(即并不会返回),直到有新客户机连接到它为止,此时会返回新的客户机socket,以及远程客户机的地址信息。 clisock, (remhost, remport) = srvsock.accept() str = cl…
2011-08-07 00:06 · Python
基础python代码
看完这段代码可以让我瞬间想起python的语法 # Open a file, read each line, and print it out for line in open('file.txt'): print line # Create a file and write to it file = open("text.txt","w") file.write("test line\n") file.close() # Create a small dictionary of names and ages and manipulate family = {'Megan':13, 'Eli…
2011-08-06 20:14 · Python
swig-python初试
swig不做介绍,python更不做介绍,自己去网上搜吧 linxu下安装swig需要的源码包在这里下 http://sourceforge.net/ 笔者下到的: wget " http://sourceforge.net/settings/mirror_choices?projectname=pcre&filename=pcre/8.12/pcre-8.12.zip " -O pcre-8.12.zip wget http://sourceforge.net/projects/swig/files/swigwin/swigwin-2.0.4/swigwin-2.0.4.zip -O sw…
2011-08-06 16:37 · Python
python处理二进制数据,读(解包),写(打包)
转自:http://muxu303.blog.163.com/blog/static/51280192011224101232405/ python作为脚本语言中最给力的一种,集成了编译语言的功能性和脚本语言的灵活性,作为一种高级的解释性脚本语言,同时还具有程序语言的各种优点如:面向对象,可扩展,可移植,易学易用,强大的内存管理,有点少叙,本文介绍其对二进制数据的操作模块struct,无论是网络应用,还是文件存储,均可派上用场.. 先来感性的认识一段代码:如下(输出为斜体) -----------------------------------------------------------…
2011-08-06 16:29 · Python
函数编程之高阶函数漫谈(Higher order functions)
IronPython和Python一样都支持多种编程范式(OOP,FP...)。本文讲述当用IronPython进行函数编程时,用到的几个基本元素:内置高阶函数(操作函数的函数:一个函数可以接受另一个函数作为参数,也可以把一个函数作为结果来返回)。这几个函数的共同点是第一个参数都是函数,并且都是对列表数据进行操作,代码简洁明了。 filter(function, iterable) filter函数有两个参数:函数,列表(可以是一个支持迭代操作的容器或者是迭代器),并且返回一个列表。其中第一个参数函数必须是单参数的函数。filter函数返回第二个参数iterable中那些使第一个参数函数返回…
2011-04-21 20:08 · Python
[Python学习]decorator的使用
在我以前介绍 Python 2.4 特性的Blog中已经介绍过了decorator了,不过,那时是照猫画虎,现在再仔细描述一下它的使用。 关于decorator的详细介绍在 Python 2.4中的What’s new中已经有介绍,大家可以看一下。 如何调用decorator 基本上调用decorator有两种形式 第一种: @A def f (): … 这种形式是decorator不带参数的写法。最终 Python 会处理为: f = A(f) 还可以扩展成: @A @B @C def f (): … 最终 Python 会处理为: f = A(B(C(f))) 注:文档上写的是@A @B…
2011-04-21 14:46 · Python