ChinaUnix.net
相关文章推荐:

python 去掉换行符

近日写一个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...

by jcodeer - Python文档中心 - 2007-10-28 23:30:08 阅读(1528) 回复(0)

各位好: 我想把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...

by 风吹不倒 - Python - 2013-07-05 21:40:19 阅读(1129) 回复(1)

我现在有这个xml文件[code] 2010.3.10[/code] 我的pyhon代码[code]#!/usr/bin/env python from xml.etree import ElementTree as ET import os def main(): xml_file = os.path.abspath(__file__) xml_file = os.path.dirname(xml_file) xml_file = os.path.join(xml_file, "problem.xml") try: tree = E...

by yangward - Python - 2010-03-22 17:23:03 阅读(2663) 回复(2)

比如有如下文件: 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! 谢谢!

by Hex - Python - 2012-05-22 12:51:17 阅读(12726) 回复(10)

本帖最后由 gdp8899 于 2013-07-11 00:14 编辑 报表日期2013-03-31 一、营业总收入27,200,800,000.00

python

by feiyang10086 - Python - 2010-12-03 10:45:30 阅读(1494) 回复(0)

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 ...

by cucugbgb - Python - 2010-11-17 09:00:00 阅读(1648) 回复(1)

#!/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") ...

by linuxccc - Linux新手园地 - 2009-09-02 16:32:22 阅读(951) 回复(2)