随笔分类 - Python
Python相关的文档
摘要:#!/usr/bin/python# Filename: using_file.pypoem = '''\Programming is funWhen the work is doneif you wanna make your work also fun:use Python!'''f = file('poem.txt', 'w') # open for 'w'ritingf.write(poem) # write text to filef.close() # close the filef =
阅读全文
摘要:一、获取当前目录下的特定文件列表>>>import glob,os>>>curdir = os.getcwd() #获取当前目录>>>os.chdir(workdir) #设置当前目录>>>dir = glob.glob('*.dat') #获取当前目录的dat文件列表>>>os.chdir(curdir) #还原当前工作目录>>>print dir['mudlog.dat','ddd.dat']二、os模块的文件和目录操作函数1.获得当前
阅读全文
摘要:对一个字符串对象,首先想到的操作可能就是计算它有多少个字符组成,很容易想到用S.len(),但这是错的,应该是len(S)。因为len()是内置函数,包括在__builtin__模块中。python不把len()包含在string类型中,乍看起来好像有点不可理解,其实一切有其合理的逻辑在里头。len()不仅可以计算字符串中的字符数,还可以计算list的成员数,tuple的成员数等等,因此单单把len()算在string里是不合适,因此一是可以把len()作为通用函数,用重载实现对不同类型的操作,还有就是可以在每种有len()运算的类型中都要包含一个len()函数。 python选择的是第一种解
阅读全文
摘要:http://www.doughellmann.com/PyMOTW/select/Purpose:Wait for notification that an input or output channel is ready.Available In:1.4 and laterTheselectmodule provides access to platform-specific I/O monitoring functions. The most portable interface is the POSIX functionselect(), which is available on U
阅读全文
摘要:linux 后台运行:nohup python s5.py 1080 &#!/usr/bin/python# Filename s5.py# Python Dynamic Socks5 Proxy# Usage: python s5.py 1080# Backgroup Run: nohup python s5.py 1080 &# Email: ringzero@557.imimport socket, sys, select, SocketServer, struct, timeclass ThreadingTCPServer(SocketServer.ThreadingM
阅读全文
摘要:额。。。。最近被python的数据类型折腾得有点够呛了。。。struct的pack和unpack可以解决很多和C兼容的数据类型问题,但是有很多trick...pack可以把一个C语言类似struct的结构转换成一个python的string数据结构,有了str结构,就可以进行write操作什么的了。from python help The optional first format char indicates byte order, size and alignment: @: native order, size & alignment (default) =: native or
阅读全文

浙公网安备 33010602011771号