python os.path模块(os.listdir和os._exit())
2017-11-22 17:00
696 查看
1.python os
fileList = os.listdir(path) if len(fileList) == 0: print 'The folder is empty' os._exit() #直接退出 Python程序,其后的代码也不会继续执行。 for file in fileList: if not os.path.isfile(path +'\\'+ file): print '文件不存在' else: print os.path.join(path+'\\',file)
更多的方法可以去查看官方文档:http://docs.python.org/library/os.path.html
python os.path模块常用方法详解:http://www.cnblogs.com/wuxie1989/p/5623435.html
2.Python os._exit() sys.exit() exit()区别
Python退出程序的方式有两种:os._exit(),sys.exit()
1)os._exit() 直接退出 Python程序,其后的代码也不会继续执行。
2)sys.exit() 引发一个 SystemExit异常,若没有捕获这个异常,Python解释器会直接退出;捕获这个异常可以做一些额外的清理工作。0为正常退出,其他数值(1-127)为不正常,可抛异常事件供捕获。
exit() 跟 C 语言等其他语言的 exit() 应该是一样的。
os._exit() 调用 C 语言的 _exit() 函数。
__builtin__.exit 是一个 Quitter 对象,这个对象的 __call__ 方法会抛出一个 SystemExit 异常。
一般来说os._exit() 用于在线程中退出
sys.exit() 用于在主线程中退出。
参考链接:http://www.cnblogs.com/gaott/archive/2013/04/12/3016355.html
3.python 的 与或非
#! /usr/bin/env python #coding=utf-8 # save file: logical_operators_example.py a = True b = False not(a and b) print ('(a and b) = ', (a and b)) print ('(a or b) = ', (a or b)) print ('not(a and b) = ', not(a and b))
相关文章推荐
- python 4-2-1 os 模块 os.listdir()/os.stat()/stat.S_IXUSR/stat.S_IXGRP/stat.S_IXOTH
- Python模块函数:os.listdir 打印Win7目录中的文件-中文乱码问题
- python os.path模块
- Python 中的 os.path 模块说明
- python的os模块fork、wait、system、exec、popen、exit函数讲解
- Python os/shutil/path 模块
- Python3-os模块与os.path
- Python os.path模块
- python os模块 以及 os.path模块 常用命令
- python os.path模块
- python3 os.path 模块常用方法汇总
- Python模块详解以及import本质,获得文件当前路径os.path.abspath,获得文件的父目录os.path.dirname,放到系统变量的第一位sys.path.insert(0,x)
- python中os.path以及sys.path模块简介
- Python: os.listdir()
- python os.path模块
- Python os.path模块
- Python os.path模块
- 【python】os和os.path模块及其常用函数方法
- python os.path模块学习
- python os.path模块常用方法详解