4 python os模块用法的一个例子
2016-11-29 09:31
417 查看
1 查看当前目录
pwd
u'/home/huxiang/work/test'
2 利用os.listdir列举当前目录所有文件
import os
file_list = [x for x in os.listdir("/home/huxiang/work/test")]
for file_name in file_list: print file_name
os.ipynb 2.py test.py input_data.py mnist1.py mnist.py others.txt~ Untitled3.ipynb Untitled1.ipynb config.py shenmu.txt~ eesen-master Untitled.ipynb shenmu.txt Untitled Document Untitled Document~ others.txt fully_connected_feed.py~ lstm_rnn.py input_data.pyc Untitled2.ipynb keep .ipynb_checkpoints yunmu.txt yunmu.txt~ mnist1.py~ 11.3 python with as的用法.ipynb cifar10 MNIST_data config.pyc fully_connected_feed.py hello.py ASR 000050275.WAV tensorboard.py
3 ls *txt
file_list = [x for x in os.listdir(dira) if x.split('.')[-1] == 'txt']
print file_list
['1.txt', '1and2.txt', '22.txt', 'shenmu.txt', 'others.txt', '2.txt', 'yunmu.txt']
相关文章推荐
- python 之 os 模块的常见用法
- python中os模块用法
- python中的os,shutil模块的定义以及用法
- python 如何重载模块,用一个简单的例子来解释
- python types模块MethodType的一个例子
- python正则表达式--基本用法和函数(一个例子)
- python 中 os 和 shutil 模块的常见用法
- Python利用OS模块模拟一个shell
- python os模块的主要用法
- python pexpect和argparse模块用法例子之确保一批远程机器指定一批服务在运行
- python3中,os.path模块下常用的用法总结
- python笔记005——os.path模块用法详解
- python中的os.path模块用法(一)
- python中os模块和sys模块的常见用法
- python re正则及os命令使用的一个小例子
- Python练习 os模块 实现一个小shell
- Python中os模块的使用(附一个调试例子)
- python os模块的主要用法
- python 中 os 和 shutil 模块的常见用法
- python http(通讯一个测试的例子Teraservertest)