码迷,mamicode.com
首页 >  
搜索关键字:os-path    ( 1357个结果
Python学习笔记2-解析数据
Import os; -- Python自带print(os.getcwd()) -- 获得当前工作目录os.chdir('/Users/longlong/Documents') -- 转换到/Users/longlong/Documents目录os.path.join(parm1, parm2,....
分类:编程语言   时间:2015-05-04 13:35:45    阅读次数:126
python 判断文件、文件夹是否存在
>>>?import?os >>>?os.path.exists(‘d:/assist‘) True >>>?os.path.exists(‘d:/assist/getTeacherList.py‘) True >>>?os.path.isfile(‘d:/assist‘) False >>>?os.path.isfile(‘d:/assist/getTeacherList.py...
分类:编程语言   时间:2015-04-29 13:45:43    阅读次数:123
python如何使用 os.path.exists()--Learning from stackoverflow
Q&A参考连接 Problem:IOError: [Errno 2] No such file or directory。os.path.exists() 如果目录不存在,会返回一个0值。 所以,如果你如下使用该函数,会得到 Problem 中描述的错误,而且错误会定位在其他地方:import os try: os.path.exists("E:/Contact") #Check if...
分类:编程语言   时间:2015-04-24 09:12:23    阅读次数:185
python 文件和路径操作函数小结
1: os.listdir(path) //path为目录 功能相当于在path目录下执行dir命令,返回为list类型 print os.listdir('..') 2: os.path.walk(path,visit,arg) path :是将要遍历的目录 visit :是一个函数指针,函数圆形...
分类:编程语言   时间:2015-04-22 17:36:09    阅读次数:156
调整目录文件时间戳脚本 python
#coding=utf-8 import sys,datetime,time,os,os.path,stat,re repattern = re.compile(r‘.*[\.]{1}([^\.]+)‘) def changeFileTime(path, ctime): for parent,dirnames,filenames in os.walk(path): ...
分类:编程语言   时间:2015-04-22 11:50:50    阅读次数:162
python查漏补缺之list列表的remove
今天碰到一个坑,python的列表问题,错误往往出在你最熟悉的地方,特别是小地方,问题:我要列出目录下所有的下一级文件和子目录(只包含下一级目录而不包括目录的目录及文件这种情况),然后只获取当前子目录。。问题描述很清楚,很轻易的就写了个函数,不就是os.listdir(path)嘛,对就是这个,这个功能可以列出下一级的所有目录和文件,返回结果在一个列表中,那我们的主要工作的常规思路是不是就是把这个结果列表进行过滤?好,os也有相关的功能,os.path.isfile(filepath),...
分类:编程语言   时间:2015-04-20 00:38:11    阅读次数:205
一个简单的python读写文件脚本
#!/usr/bin/env python 'makeFile.py -- create a file' import os ls = os.linesep # get filename while True: fname = raw_input('Input an unused file name >') if os.path.exists(fname): print "ERROR...
分类:编程语言   时间:2015-04-17 15:52:14    阅读次数:161
[Python练习]对比两个目录里面的文件差异,并给出差异列表
#!/usr/bin/envpython importos importsys defget_Curlist(path): cur_Files=os.listdir(path) all_Files=[] forfile_Nameincur_Files: full_Name=os.path.join(path,file_Name) all_Files.append(full_Name) ifos.path.isdir(full_Name): next_Levelfiles=get_Curlist(full_..
分类:编程语言   时间:2015-04-15 11:36:05    阅读次数:157
django settings最佳配置
# encoding=utf-8import osimport socketSITE_ID = 1# 项目的根目录# 简化后面的操作PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))# 加载应用# 把应用添加到INSTALLED_APP...
分类:其他好文   时间:2015-04-14 00:30:55    阅读次数:212
Python遍历目录的4种方法
1.os.popen运行shell列表命令deftraverseDirByShell(path):forfinos.popen(‘ls‘+path):printf.strip()2.利用glob模块glob.glob(path)返回带目录的文件名.通配符和shell相似.path不能包含shell变量.deftraverseDirByGlob(path):path=os.path.expanduser(path)forfinglob(path+‘/..
分类:编程语言   时间:2015-04-13 13:05:07    阅读次数:142
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!