Python 重写C语言经典 Question
摘要:Question 001:#!/usr/bin/env python#--*-- coding:utf-8 --*--"""1,2,3,4数字,能组成多少个互不相同且无重复数字的三位数字?都是多少?"""for i in range(1,5): for j in range(1,5): for k...
阅读全文
Setting and getting the default socket timeout
摘要:#!/usr/bin/env python import socketdef test_socket_timeout(): s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) print "Default socket timeout:%s"% ...
阅读全文
Converting integers to and from host to network byte order
摘要:#!/usr/bin/env pythonimport socketdef convert_integer(): data = 1234 #32bit print "Original:%s =>Long host byte order:%s, Network byte order:\ order:%...
阅读全文
Finding a service name, given the port and protocol
摘要:#!/usr/bin/env pythonimport socketdef find_service_name(): protocolname = 'tcp' for port in [80,25]: print "Port:%s => service name: %s" %(port,socke...
阅读全文
Converting an IPv4 address to different formats
摘要:#!/usr/bin/env pythonimport socketfrom binascii import hexlifydef convert_ipv4_address(): for ip_addr in ['127.0.0.1','192.168.0.1']: packed_ip_addr ...
阅读全文
Python GET REMOTE SERVER'S INFO
摘要:1 #!/usr/bin/env python 2 #--*-- coding:utf-8 --*-- 3 # Python Network Programming Cookbook -- Chapter – 1 4 # This program is optimized for Python 2...
阅读全文
Python Network Programming -Gethostname&ip_address
摘要:#!/usr/bin/env python#python network programming cookbook -- chapter -1#this program is optimized for Python 2.7 it may run on any#other python versio...
阅读全文
Operations on basic server (by Python)
摘要:#!/usr/bin/env python#Simple server -Chapter 1 -server.pyimport sockethost = ''port = 51423s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)s.setso...
阅读全文
OS X 黑科技 使用bash 播放mp3
摘要:1.what do we need? sox2.how to install? sudo brew install sox (you can also download sox from sourceforge,but probably you may come into some depend...
阅读全文
Thread
摘要:一、没有线程的支持的例子: #!/usr/bin/env pythonfrom time import sleep,ctimedef loop0(): print 'start loop 0 at:',ctime() sleep(4) print 'loop 0 done at:',ctime()...
阅读全文
Mac OS X 安装brew
摘要:1.Why? 网上写的教程都参差不齐,所以自己写了一下纯粹当做笔记。2.How? 1).打开网址:http://github.com/mxcl/homebrew/tarball/master 会自动将一个名字为"Homebrew-homebrew-2871e09.tar"下载下来 2)....
阅读全文
How to Customize your Terminal Prompt
摘要:Whether you use the Terminal occasionally or regularly, you might find it appropriate to change the way it looks beyond the color scheme and transpare...
阅读全文
Python build-in function filter()
摘要:#!/usr/bin/env python #--*-- coding:utf-8 --*--#version one"""from random import randintdef odd(n): return n%2allNums = []for eachNum in range(9): ...
阅读全文
信用卡交易系统 Python
摘要:#!/usr/bin/env python#--*-- coding:utf-8 --*--#safe_float 的函数主体def safe_float(obj): 'safe version of float()' try: retval = float(obj) ...
阅读全文
Python 模拟登陆数据系统
摘要:#!/usr/bin/python#--*-- coding:utf-8 --*--"""此程序管理用于登陆系统的用户信息:登陆名字和密码。登陆用户账号建立后,已存在用户可以用登陆名字和密码重返系统。新用户不能用别人的登录名建立用户账号"""db = {}def newuser(): prom...
阅读全文
Python 内建函数cmp()
摘要:>>>list1,list2 = [123,'xyz'],[456,'abc']>>>cmp(list1,list2)-1>>>cmp(list2,list1)>>>1>>>list3 = list2 + [789]>>>list3[456,'abc',789]>>>cmp(list2,list3)...
阅读全文
Python Simple Unicode Instance
摘要:#!/usr/bin/env python#--*-- coding:utf-8 --*--'''An example of reading and writing Unicode string :Writes a Unicodestring to a file in utf-8 and reads...
阅读全文
Python 论字符串不变性
摘要:>>>'abc' + 'def''abcdef'Python分别为'abc'和'def'分配了空间,当进行连接操作时,Python自动为新的字符串'abcdef'分配了空间>>>s = 'abc'>>>s = s + 'def'>>>s'abcdef'上面的例子中,看上去我们把'abc'赋给了s,然...
阅读全文
Python 效率
摘要:while i < len(myString): print 'character %d is:'%myString[i]length = len(myString)while i < length: print 'character %d is:'%myString[i]for oth...
阅读全文
idcheck 标识符合法性检查
摘要:#!/usr/bin/env python#--*-- coding:utf-8 --*--"""标识符合法性检查,首先要以字母或者下划线开始,后面要跟字母,下划线或者数字这个例子只检查长度大于等于2的标志符"""import stringalphas = string.letters + '_'n...
阅读全文
How to install rar in OSX Yosemite
摘要:1. first of all, you need to download the right version of rar for mac os x. the download url:www.rarlab.com2.it is really a pity that the rar is jus...
阅读全文
Python Core Programing Chapter 0_4 Test
摘要:Question 0_1: Python 对象。与所有Python对象有关的三个属性是什么?请简单描述Answer:Question 0_2: 类型。不可更改(immutable)指的是什么?Python的哪些类型是可更改的(mutable),哪些不是?Answer:Question 0_3: 类型...
阅读全文