Python初学教程:Python使用os.path处理文件路径,pythonos.path,Python使用os.p
Python初学教程:Python使用os.path处理文件路径,pythonos.path,Python使用os.p
Python使用os.path处理文件路径
如下是os.path的使用示例:
#!/usr/bin/python# python 的os.path用来处理文件名from os.path import *for fn in [ '/', '/home/bennet', 'path.py', '/var/log/messages', 'bogus' ]: print '%-15s' % fn + ':', # 判断路径是否存在 if exists(fn): print 'exists,', else: print 'nonexistent' print continue # 判断路径是否是绝对路径 if isabs(fn): print 'absolute,', print 'directory', dirname(fn)+',', 'base', basename(fn)+',' print ' ' * 16, else: print 'relative,', # 判断路径是文件还是目录 if isfile(fn): print 'plain file,', elif isdir(fn): print 'directory,', else: print 'strange,', # 获得扩展名 print 'extension', splitext(fn)[1]+',', # Size print getsize(fn), 'bytes.' print
相关内容
- Python验证Url地址的正则表达式,python正则表达式,Pytho
- Python连接mysql OperationalError: (1366, "Incorrect string
- Python使用easy_install升级包,pythoneasy_install,easy_install
- Python实现java或者.net的getHashCode()函数,pythongethashcode,
- Python正则表达式入门,python正则表达式,一. 编译正则表
- Python使用elaphe包生成二维码,pythonelaphe,首先需要安装
- Python正则表达式前向否定断言使用示例,python正则表达
- python itertools模块学习笔记,pythonitertools,python itert
- Decorate an output stream with print-like methods,decorateprint-lik
- Python合并两个字典,python合并字典,Python合并两个字典
评论关闭