ChinaUnix.net
相关文章推荐:

python列出文件目录下的文件列表

os和os.path模块 os.listdir(dirname):列出dirname下的目录文件 os.getcwd():获得当前工作目录 os.curdir:返回但前目录('.') os.chdir(dirname):改变工作目录到dirname os.path.isdir(name):判断name是不是一个目录,name不是目录就返回false os.path.isfile(name):判断name是不是一个文件,不存在name也返回false os.path.exists(name):判断是否存在文件目录name os.path.getsize(name):获得文件大小,如果name是目录返回0...

by zieckey - Python文档中心 - 2009-07-24 09:06:28 阅读(1464) 回复(0)

相关讨论

客户端从服务器获取服务器的文件目录列表 参数是目录路径 返回路径下的文件列表. 如果参数是个文件的路径,返回文件的属性及大小 用HTTP服务

by summer85 - Python - 2008-07-21 11:29:10 阅读(2308) 回复(2)

import os import time file = "samples/sample.jpg" def dump(st): mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = st print "- size:", size, "bytes" print "- owner:", uid, gid print "- created:", time.ctime(ctime) print "- last accessed:", time.ctime(atime) print "- last modified:", time.ctime(mtime) print "- mode:", oct(mode) print "- inode/dev:"...

by blueycx - Python文档中心 - 2008-12-08 22:45:38 阅读(2016) 回复(0)

目标:查找指定目录下的指定模式的文件,替换文件中的部分内容 初学,python的OO还用不熟悉,结构有点乱,等有空再重构,今天总算先把任务完成再说 #!/usr/bin/env python import os, sys,fnmatch __author__ = "hf_linux (hf_linux@yahoo.com.cn)" __version__ = "$Revision: 0.1 $" __date__ = "$Date: 2006/09/06 20:07:19 $" __copyright__ = "Copyright (c) 2006 hf_linux" __license__ = "python" class repDirStr: ...

by hanyh - Python文档中心 - 2006-09-06 20:24:20 阅读(2560) 回复(0)

这是上周四没发成功的帖子。 现在工作的东西需要把策划文档中的Excel内容按列形成数组。考虑到有几个像这样的独立部分,并且以后修改的可能性也很大,正好可以用python来方便地完成这个任务。 举个例子,比如:原来的文件是从Excel拷贝出来存为 parseWordGroup.txt,内容: 鹅 毛 河 南 方 鸡 江 南 人 青 草 鹅 青 色 方 红 花 子 花 草 色 则会生成result.txt: c1Array = ["鹅","南","江","青","青","红","花"] c2Array ...

by wibrst - Python文档中心 - 2006-12-25 10:02:35 阅读(1317) 回复(0)

import shutil import os def copyfile(file,path): if os.path.exists(file): os.rmdir(file) else: shutil.copyfile('file', 'path') print "copy %s to %s successful" % (file,path) 我这个脚本有问题吗? 或者: 1 #!/usr/bin/python 2 # -*- coding: UTF-8 -*- 3 import shutil 4 import os 5 #def copyfile(file,path): 6 dirnow=os.getcwd() 7 print d...

by blueskysee - Python - 2009-07-09 15:06:53 阅读(6202) 回复(2)

import os os.path.isfile('a.txt') #如果不存在就返回False os.path.exists(directory) #如果目录不存在就返回False 基本上对文件目录等操作都在os包下 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93327/showart_1843421.html

by 老衲法号SE - Python文档中心 - 2009-02-25 17:27:41 阅读(2712) 回复(0)

列表和元组有几处重要的区别。列表元素用中括号( [ ])包裹,元素的个数及元素的值可 以改变。元组元素用小括号(( ))包裹,不可以更改(尽管他们的内容可以)。元组可以看成是 只读的列表。通过切片运算( [ ] 和 [ : ] )可以得到子集,这一点与字符串的使用方法一样。 >>> aList = [1, 2, 3, 4] >>> aList [1, 2, 3, 4] >>> aList[0] 1 >>> aList[2:] [3, 4] >>> aList[:3] [1, 2, 3] >>> aList[1] = 5 >>> aList [1, 5, 3, 4] 元组...

by kinganeng - Python文档中心 - 2009-04-15 16:42:15 阅读(1350) 回复(0)

常见列表常量和操作 (1) 操作 解析 L1 = [] 一个空的列表 L2 = [0,1,2,3] 四项: 索引为0到3 L3 = ['abc', ['def','ghi']] 嵌套的子列表 L2, L3[j] 索引 L2[i:j] 分片 len(L2) 求长度 常见列表常量和操作 (2) 操作 解析 L1 + L2, L2 * 3 for x in L2, 3 in L2 ------------- L2.append(4), L2.sort(), L2.index(1), L2.reverse() ------------- del L2[k], L2[i:j] = [] ------------- L2 = 1, L2[i:j] = ...

by lvDbing - Python文档中心 - 2008-09-02 22:16:14 阅读(1469) 回复(0)

comp.lang.python                   http://groups.google.com/group/comp.lang.python python-chinese@lists.python.cn     中国python用户组开发人员 python-cn@googlegroups.com         Chinese python User Group CPUG@g...

by 23号 - Python文档中心 - 2007-10-22 12:24:41 阅读(2926) 回复(0)

python列表过滤 methodList = [method for method in dir(object) if callable(getattr(object, method))] 如果了解shell的话,这个将很好理解: for method in dir(object) do if [ callable(getattr(object, method)) ];then print $method fi done 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/12592/showart_136385.html

by CUDev - Python文档中心 - 2006-07-04 18:45:59 阅读(1237) 回复(0)