免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: lan97
打印 上一主题 下一主题

求 python 遍历文件属性的办法 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-06-22 10:58 |只看该作者

个人认为3.0b1 下实现最简单的方法,求最简单的实现方法

print([object, ...][, sep=' '][, end='n'][, file=sys.stdout])
Print object(s) to the stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no object is given, print() will just write end.

The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used.
IDLE 3.0b1  

个人认为3.0b1 下实现最简单的方法,求最简单的实现方法

>>> import os
>>> import time
>>> f=os.listdir('d:\\')
>>> a=open('c:\\a.csv','w')
>>> for row in f:
        i=os.path.join('D:\\',row)
        o=time.gmtime(os.path.getctime(i))
                t=time.strftime("%Y%m%d",o)
        print(row,t,sep=',',file=a)
>>>

文件写入 a.csv
Foxmail        20070515
语音        20061113
Recycled        20030814
Downloads        20070516
Program Files        20070516
hp打印机        20070703
17173游戏下载站        20070526
Favorites        20070515
My Documents        20070515
kabasiji6.0.2.621        20071024
TDdownload        20071025
Beyond.csv        20080622
KV-Back.vir        20031029
My Music        20030930
System Volume Information        20031027

[ 本帖最后由 lan97 于 2008-6-22 11:42 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP