近日写一个python的小程序,把一个list通过struct.pack写到文件里,可是每次写出来后,文件都比我写进去的字节数多了2;输出文件前先print出来数据来,都是对的。于是直接用winhex观察文件,发现每个0x0a的直接前,都加入了一个0x0d. 一番冥想后才明白原来我用的file.open是没有用"wb"模式,而只是用了"w".这时作为字符串输出,于是 python聪明的在每个行结尾(0x0a)前加了个0x0d,变成window系统的有效行结束符! 一...
by vinge - Python文档中心 - 2009-11-02 00:17:39 阅读(2722) 回复(0)
1.接收以换行符为结束表示的字符串(服务器端) # -*- coding: cp936 -*- """ 接收以断行符作为结束标识的字符串 为了演示多次接收数据,故意将接收的缓冲区改小为20. 客户端发送的数据长度(以"\n"作为判断长度的表示,而不是NULL)应该大于20 """ import socket import sys host = "" port = 50000 s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.bind((host,port)) s.listen(5) while 1: clientsock,clientaddr = s.a...
各位好: 我想把python的进程名修改掉,比如 python test.py 1 2 3 改为 pytest 在网上搜到一些信息,能把进程名改掉[code]import os, sys proc='pytest' if not os.environ.has_key('NEWPROCNAME'): os.execlpe(sys.executable, procname, __file__, {'NEWPROCNAME': procname})[/code]但参数依然保留了,变成了pytest 1 2 3 请问如何能把它的参数也去除显示 从os的文档看,类似的方法都是自动带参数了[c...
我现在有这个xml文件[code]
比如有如下文件: This is the fist line this is second line and with some space in the front hi! I'm the 3rd line! 变成: This is the fist line this is second line and with some space in the front hi! I'm the 3rd line! 谢谢!
本帖最后由 gdp8899 于 2013-07-11 00:14 编辑
python is是种很特殊的语法,你在其它的语言应该不会见到这样的用法,今天就来说说这个把。 python is 按照自字面的意思就是什么东西是什么的,比如he is a boy,他是一个大男孩,而我们一般在写python程序的时候,也会用到一些判断,有的时候也会用到python is,比如判断下这个字符是否为none。 下面是python is的例子,比如我们来判断下一个字符串。 a = 'abc' if a is not None: print 'a is not none' 输出的结果是 a is not ...
#!/urs/bin/python contact = {} contact_list = [] select = ['1.insert','2.delete'] for i in select: print i print 'what\'s your choise:' get = raw_input('1 or 2') if get == 1: test = 1 while test==1: contact['name'] = raw_input("please input name: ") contact['phone'] = raw_input("please input phone number: ") contact_list.append(contact.copy()) go_on = raw_input("continue?\n") ...