摘要: 1 ''' 2 将当前目录的所有扩展名为html的文件重命名为扩展名为htm的文件 3 方法一 4 ''' 5 import os 6 file_list=os.listdir('.') 7 for filename in file_list: 8 pos=filename.rindex(".") 9 if filename[pos+1:] =="html": ... 阅读全文
posted @ 2017-06-13 22:55 JustLittle 阅读(742) 评论(0) 推荐(0)
摘要: 1 import os 2 import os.path 3 print(os.path.basename('/Users/c2apple/Desktop/彩屏')) #获取路径的最后一个组成部分 4 os.path.exists('test1.txt') #测试文件是否存在 5 os.rename('data.txt','sample1.txt') #os.renamme... 阅读全文
posted @ 2017-06-13 14:56 JustLittle 阅读(454) 评论(0) 推荐(0)
摘要: 1 ''' 2 os模块除了提供使用操作系统功能和访问文件系统的简便方法之外,还提供了大量文件与文件夹操作的方法。 3 os.path模块提供了大量用于路径判断、切分、连接以及文件夹遍历的方法。 4 shutil模块也提供了大量的方法支持文件和文件夹操作 5 ''' 6 ''' 7 access(path,mode) 按照mode指定的权限访问文件 8 chdir(path)... 阅读全文
posted @ 2017-06-12 20:16 JustLittle 阅读(483) 评论(0) 推荐(0)
摘要: 1 import marshal #导入模块 2 x1=30 #待序列化的对象 3 x2=5.0 4 x3=[1,2,3] 5 x4=(4,5,6) 6 x5={'a':1,'b':2,'c':3} 7 x6={7,8,9} 8 x=[eval('x'+str(i)) for i in range(1,7)] #把需要序列化的对象放在一个列表中 9 print(x)... 阅读全文
posted @ 2017-06-12 14:27 JustLittle 阅读(643) 评论(0) 推荐(0)
摘要: 1 import shelve #导入shelve模块 2 fp=shelve.open('shelve_test.dat') #创建或打开二进制文件 3 zhangsan={'age':38,'sex':'Male','adress':'SDIBT'} 4 fp['zhangsan']=zhangsan #写入文件内容 5 lisi={'age':40,'sex':'male... 阅读全文
posted @ 2017-06-12 14:11 JustLittle 阅读(230) 评论(0) 推荐(0)
摘要: n= 130000000 x= 96.45 b= True s= a1@中国 9 9 阅读全文
posted @ 2017-06-11 23:56 JustLittle 阅读(2855) 评论(0) 推荐(0)
摘要: 将文本文件转化为二进制文件 阅读全文
posted @ 2017-06-11 22:23 JustLittle 阅读(16650) 评论(2) 推荐(0)
摘要: 1 filename='demo.py' 2 with open(filename,'r')as fp: 3 lines=fp.readlines() #读取所有行 4 maxLength=max(map(len,lines)) #最长行的长度 5 for index,line in enumerate(lines): #遍历所有行 6 newLine=line.... 阅读全文
posted @ 2017-06-10 17:20 JustLittle 阅读(4982) 评论(0) 推荐(0)
摘要: 用MAC电脑内的Numbers打开name.csv文件效果图 阅读全文
posted @ 2017-06-10 16:47 JustLittle 阅读(853) 评论(0) 推荐(0)
摘要: 1 ''' 2 假设文件data.txt中有若干整数,整数之间使用英文逗号分隔、编写程序读取所有整数,将其按升序后再写入文本文件datta_asc.txt中 3 ''' 4 import random 5 countNum = 0 6 with open('data.txt','a+') as fp: 7 while True: 8 countNum +=... 阅读全文
posted @ 2017-06-10 15:54 JustLittle 阅读(1477) 评论(0) 推荐(0)