Rendering of reStructured text is not possible, please install Docutils.
:status: 草稿;ZoomQuiet; 90%
.. contents::
:depth: 3
-4 PyDay 可用的首个脚本
===============================
**寻找吧!不要先想着创造--Python 是自足的**
现在的需求
--------------------
嗯嗯嗯! 小白根据曾经下载过的几个类似商业软件名称, 给自个儿的软件起个名字: **CDCategory** -- 光盘分类库,简写 CDC
再确认当前的需求 ::
1. 可以将光盘内容索引储存为硬盘上的文本文件
2. 可以根据储存到硬盘上的光盘信息进行搜索
第一需求是将光盘信息读取为文本文件,因为小白痛恨DB;-)
文件是系统的事儿
----------------------------------------
现在首先的问题是 **如何读取指定目录/分区中的文件列表信息?**
行者仅仅给了一点批示-- **文件是系统的事儿**
listdir()
``````````````````````````````````````````
系统 -- 操作系统 -- operating system -- `os模块`_
呜乎矣哉! 小白搜索了一大圈才弄明白,什么叫 **系统** , 而且找到了相应的 **模块**
在简明 Python 教程--第14章 Python标准库 -- `os模块`_ 中看到一句话 ::
os.listdir()返回指定目录下的所有文件和目录名
看起来可以使用所以,创建我们第一个执行脚本 **PyDay-4-1.py** ::
# coding : utf-8
import os
print os.listdir("/media/cdrom0")
运行结果类似:
截屏2-1 |snap_example1|
当然使用 iPython 环境,逐步运行也一样
截屏2-2 |snap_exampleipy1|
walk !
``````````````````````````````````````````
-4 PyDay小结
===============================
练习
--------------------
.. os模块:http://www.woodpecker.org.cn:9081/doc/abyteofpython_cn/chinese/ch14s03.html
.. iPython:http://ipython.scipy.org/moin/
.. |snap_example1| image:: snap_example1.png
.. |snap_exampleipy1| image:: snap_exampleipy1.png
脚注 [#]_
.. [#] If that relative link doesn't work, try the master document:
http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html.
.. macro:: [[PageComment2(nosmiley=1, notify=1)]]
.. macro:: -- ZoomQuiet [[[DateTime(2007-02-20T07:11:54Z)]]]