Files are organized into directories (also called ‘folders’). Every running program has a ‘current directory’, which is the default directory for most operations. For example, when you create a new file with open, the new file goes in the current directory. And when you open a file for reading, Python looks for it in the current directory. The module os provides functions for working with files and directories. os.getcwd returns the name of current directory. cwd stands for ‘current working directory’. A string like cwd that identifies a file is called a path. A relative path starts from the current directory; an absolute path starts from the topmost directory in the file system. The paths we have seen so far are simple filenames, so they are relative to the current directory. To find the absolute path to a file, you can use abspath, which is in the module os.path.

To demonstrate these functions, the following examples ‘walks’ through a directory, prints the names of all the files, and calls itself recursively on all the directories.

from Thinking in Python

Filenames and paths的更多相关文章

  1. 非常全面的SQL Server巡检脚本来自sqlskills团队的Glenn Berry 大牛

    非常全面的SQL Server巡检脚本来自sqlskills团队的Glenn Berry 大牛 Glenn Berry 大牛会对这个脚本持续更新 -- SQL Server 2012 Diagnost ...

  2. Java魔法堂:URI、URL(含URL Protocol Handler)和URN

    一.前言 过去一直搞不清什么是URI什么是URL,现在是时候好好弄清楚它们了!本文作为学习笔记,以便日后查询,若有纰漏请大家指正! 二.从URI说起    1. 概念 URI(Uniform Reso ...

  3. minicom 使用教程

    因为现在电脑基本不配备串行接口,所以,usb转串口成为硬件调试时的必然选择.目前知道的,PL2303的驱动是有的,在dev下的名称是ttyUSB#. minicom,tkterm都是linux下应用比 ...

  4. ubuntu下minicom和USB转串口(转)

    ubuntu下minicom和USB转串口(转)   minicom是linux下串口通信的软件,它的使用完全依靠键盘的操作,虽然没有“超级终端”那么易用,但是使用习惯之后读者将会体会到它的高效与便利 ...

  5. linux 使用串口连接设备console

    linux使用串口连接cisco设备的console   linux 自带一个串口命令:minicom,需要经过设置,之后就可以连接了.   传说是默认就可以,我可能RP不好,我必须要经过设置才可以. ...

  6. Centos6.5 minicom安装与配置

    Linux下的Minicom的功能与下的超级终端功能相似,适于在通过超级终端对设备的管理以及对嵌入操作系统的升级 1.minicom的安装 查看是否安装:   rpm -qa | grep minic ...

  7. minicom installation and configuration on ubuntu

    minicom是一个串口通信工具,就像Windows下的超级终端,可用来与串口设备通信.minicom完全通过键盘实现操作. install sudo apt-get install minicom ...

  8. JZ2440开发笔记(2)——minicom的安装和配置使用【转】

    一.安装配置minicom 1.安装minicom lingd@ubuntu:~$ sudo apt-get install minicom 2.配置minicom lingd@ubuntu:~$ s ...

  9. 虚拟机下ubuntu的minicom使用指南

    整理自ubuntu下的minicom的使用 minicom是linux下串口通信的软件,它的使用完全依靠键盘的操作,虽然没有"超级终端"那么易用,但是使用习惯之后读者将会体会到它的 ...

随机推荐

  1. STL_算法_对全部元素排序(sort、stable_sort)

    C++ Primer 学习中. . .   简单记录下我的学习过程 (代码为主) //大部分容器适用.不适用于list容器 sort(b,e) sort(b,e,p) stable_sort(b,e) ...

  2. iOS给label加入下划线

    UILabel *myLabel = [[UILabelalloc] ,, , )]; NSMutableAttributedString *content = [[NSMutableAttribut ...

  3. web forms page和control的生命周期life cycle交互,以及page生命周期中每个event中需要做什么事情

    只有 page_load和page_init这些可以autoeventwireup RenderControl只提供override public override void RenderContro ...

  4. JAVA设计模式之【策略模式】

    策略模式 定义一些独立的类来封装不同的算法 类似于common方法或者引用类 角色 环境类Context 抽象策略Strategy 具体策略ConcreteStrategy 重构伴随着设计模式 重构类 ...

  5. 安装Oracle RAC 11g

    1.Oracle Enterprise Linux 和 iSCSI 上构建 Oracle RAC 11g 集群 2.Oracle RAC 的所有共享磁盘存储将基于 iSCSI,iSCSI 使用在第三个 ...

  6. Eclipse下载安装教程

    Eclipse下载安装 Eclipse是一款开源软件,免费,实用,也应该是大多数同学接触的第一款java集成开发环境(IDE),简单介绍下下载流程 1.进入官网 百度,Bing,或谷歌搜索Eclips ...

  7. xBIM 实战01 在浏览器中加载IFC模型文件

    系列目录    [已更新最新开发文章,点击查看详细]  一.创建Web项目 打开VS,新建Web项目,选择 .NET Framework 4.5  选择一个空的项目 新建完成后,项目结构如下: 二.添 ...

  8. C++ STL next_permutation() prev_permutation(a,a+n)用法。

    int a[3] = {1,2,3}; a可能形成的集合为{1,2,3},{1,3,2},{2,1,3},{2,3,1},{3,1,2},{3,2,1}. {2,1,3}的prev是{1,3,2}, ...

  9. python内置的一些模块

    logging模块: 默认情况下,logging将日志打印到屏幕,日志级别为WARNING:日志级别大小关系为:CRITICAL > ERROR > WARNING > INFO & ...

  10. vue 锚点定位

    vue 锚点定位 <template> <div class="details"> <div class="wrapper w"& ...