码迷,mamicode.com
首页 >  
搜索关键字:readlines    ( 570个结果
fileinput模块
fileinput模块可以遍历文件的所有行,跟readlines类似,不同在于readlines是将文件读取的行全部放到一个列表里,而fileinput是创建了一个xreadlines对象下面是fileinput模块中的常用函数input()#它会返回能够用于for循环遍历的对象.filename()#返回当前文件的名称lineno()#返回..
分类:其他好文   时间:2014-09-17 15:37:33    阅读次数:208
L01-04:python查询员工信息表练习
#decoding=utf-8‘‘‘编写可供用户查询的员工信息表!1|用户认证IDNamedepartmentphone查询关键字:姓名‘‘‘importlinecache input01=raw_input("plswriteyourname:") i=1 name=[] count=len(open(‘user.txt‘,‘rU‘).readlines()) whilei<=count: fline=linecache.getline("user..
分类:编程语言   时间:2014-09-05 03:20:01    阅读次数:203
python multiprocessing多进程 ssh
importmultiprocessingimporttime,datetimedefSsh_Cmd(host,CmdFile):elog=open(‘error.log‘,‘a+‘)log=open(‘7z.log‘,"a+")forCmdinopen(CmdFile).readlines():Cmd=Cmd.strip()ifnotlen(Cmd)orCmd.startswith(‘#‘):continuessh=paramiko.SSHClient()ssh.set_missing_host_key_p..
分类:编程语言   时间:2014-08-26 19:54:07    阅读次数:326
Python Numpy ValueError: data type must provide an itemsize
天朝网络锁国,百度找了半个小时找不出来原因,只能谷歌谷歌第一条就是,顿时感觉幸福感来的太突然原因是输入的矩阵均是字符串(从文件里读的)那么就需要批量转数组,一行一行的转。下面是我的代码:rownum = 0f = open(train_Y_path)for line in f.readlines()...
分类:编程语言   时间:2014-08-01 18:40:22    阅读次数:1024
Python基础
也是自己之前学习的笔记。读文件file_obj2=open('hello.txt','w')conta='my name is Bb'file_obj2.write(conta)v=file_obj2.readlines()print v输出不唯一数1 (这是一个国外Python练习网站上的题...
分类:编程语言   时间:2014-07-23 22:21:17    阅读次数:497
python的文件管理
1.seek(offset,where)where=0,1从当前位置移动,2从结束位置移动当有换行时,会被截断。seek()无返回值,值为None2.tell()文件的当前位置,tell是获得文件指针位置,受seek,readline,read,readlines影响,不受truncate影响3.truncate(n)从文件的首行首字符开始截断..
分类:编程语言   时间:2014-07-17 09:00:22    阅读次数:288
python 之 函数
deffm(): #定义一个函数fm()这个函数的内容是以下一个脚本。 foriinrange(0,6): fr=open("qg/t.txt",‘r‘) #打开一人文件并读取 print(fr.readlines()[5-i]) #显示这个文件的内容,是从最后5行显示到第1行。这个文件只有5行。 fr.close() #关闭这个打开的文件。 #定义函数fm,..
分类:编程语言   时间:2014-07-04 06:21:02    阅读次数:240
python的第一个脚本
第一个简单的python脚本#!/usr/bin/python # importos file_1=‘user.txt‘ file_2=‘lock.txt‘ #putanaccount_list f=file(file_1) accout_list=f.readlines() f.close() #putalistofthelockuser f=file(file_2) lock_list=[] foriinf.readlines(): line=i.strip(‘\n‘) lock_list..
分类:编程语言   时间:2014-05-21 01:19:11    阅读次数:391
graphite,python监控网卡流量
#!/usr/bin/envpythonimportsys,timefromsocketimportsocketdefread_interface(in_file):withfile(in_file)asf:returnf.readlines()[2:]defset_interface(inter_msg):dic={}foriinxrange(len(inter_msg)):dic[inter_msg[i].split(":")[0].strip()]={"in":inter_msg[i].split(":..
分类:编程语言   时间:2014-05-13 04:01:55    阅读次数:432
python学习笔记
将文件的每行读取到字典中文件每行内容格式为:cui:123456789f=open(‘user.txt‘) d=f.readlines() f.close() mydict={} foriind: user=i.split(‘:‘)[0] info=i.split(‘:‘)[1].rstrip() mydict[user]=info
分类:编程语言   时间:2014-05-06 16:40:26    阅读次数:362
570条   上一页 1 ... 55 56 57
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!