每天学习一个python的类(大多数都是第三方的),聚沙成金。

--------------------------------------------------------------------------------

今天学习的是:pathlib:(Python3.4+ 标准库)跨平台的、面向对象的路径操作库.

其官方网址为:https://pathlib.readthedocs.io/en/pep428/

如果只是把path作为string对象来操作,我们会碰到很多很繁琐的操作,因此,pathlib就是对os.path进行了封装,提供了一个便捷的,面向对象的操作方式

而且,从python3.4开始,这个类就是标准类库了

his module offers classes representing filesystem paths with semantics appropriate for different operating systems. Path classes are divided between pure paths, which provide purely computational operations without I/O, and concrete paths, which inherit from pure paths but also provide I/O operations

几个常见的例子:

 from pathlib import *

 p=Path('.')
for x in p.iterdir():
if x.is_dir():
print(x)

显示某个路径下的py的源文件

 list(p.glob('*.py'))

其源代码的引入的类如下;
import fnmatch #fnmatch 模块使用模式来匹配文件名.
import functools 用于高阶函数:指那些作用于函数或者返回其它函数的函数,通常只要是可以被当做函数调用的对象就是这个模块的目标。
import io
import ntpath
import os
import posixpath
import re
import sys
import time
from collections import Sequence
from contextlib import contextmanager
from errno import EINVAL, ENOENT
from operator import attrgetter
from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
try:
from urllib import quote as urlquote, quote as urlquote_from_bytes
except ImportError:
from urllib.parse import quote as urlquote, quote_from_bytes as urlquote_from_bytes

python每日一类(1):pathlib的更多相关文章

  1. python每日一类(4):slice

    class slice(stop)class slice(start, stop[, step]) Return a slice object representing the set of indi ...

  2. python每日一类(3):os和sys

    os与sys模块的官方解释如下: os: This module provides a portable way of using operating system dependent functio ...

  3. python每日一类(2):platform

    根据官方文档的解释(https://docs.python.org/3.5/library/platform.html#module-platform): 学习其他人的代码如下: # python p ...

  4. python每日一类(5):itertools模块

    itertools模块包含创建有效迭代器的函数,可以用各种方式对数据进行循环操作,此模块中的所有函数返回的迭代器都可以与for循环语句以及其他包含迭代器(如生成器和生成器表达式)的函数联合使用. ch ...

  5. Python每日一练(1):计算文件夹内各个文章中出现次数最多的单词

    #coding:utf-8 import os,re path = 'test' files = os.listdir(path) def count_word(words): dic = {} ma ...

  6. python每日一函数 - divmod数字处理函数

    python每日一函数 - divmod数字处理函数 divmod(a,b)函数 中文说明: divmod(a,b)方法返回的是a//b(除法取整)以及a对b的余数 返回结果类型为tuple 参数: ...

  7. python每日一练:0007题

    第 0007 题: 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码.包括空行和注释,但是要分别列出来. # -*- coding:utf-8 -*- import os def count ...

  8. [python每日一练]--0012:敏感词过滤 type2

    题目链接:https://github.com/Show-Me-the-Code/show-me-the-code代码github链接:https://github.com/wjsaya/python ...

  9. Python 每日一练 | Flask 实现半成品留言板

    留言板Flask实现 引言 看了几天网上的代码,终于写出来一个半成品的Flask的留言板项目,为什么说是半成品呢?因为没能实现留言板那种及时评论刷新的效果,可能还是在重定向上有问题 或者渲染写的存在问 ...

随机推荐

  1. MyBatis---简单增删改查的带事物的例子

    本例子包含了对数据库表简单的增删改查的操作,并且包含事物.该例子只适用于MySQL数据库.该例子需要手动创建数据库以及数据库表 例子中所需要的jar包,详查MyBatis---简介 一个entity类 ...

  2. 如何在 Eclipse 中使用插件构建 PHP 开发环境[转]

    原文出处: http://hykloud.com/2012/03/08/information_technology/how-setup-eclipse-php-pdt-remote-system-e ...

  3. 《Cracking the Coding Interview》——第16章:线程与锁——题目4

    2014-04-27 20:06 题目:设计一个类,只有在不产生死锁的时候才分配资源. 解法:不太清楚这个题是要分配何种资源,以何种形式?所以没能动手写个可运行的代码,只是闲扯了几句理论分析. 代码: ...

  4. 重现ssd遇到的问题

    首先是create_list.sh和create_data.sh中的data_dir的路径得修改. 然后是在create_data.sh文件调用$caffe_root下的scripts目录中的crea ...

  5. PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名

    题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...

  6. C++ 虚继承内存分配

    我们知道,虚继承的基类在类的层次结构中只可能出现一个实例.虚基类在类的层次结构中的位置是不能固定的,因为继承了虚基类的类可能会再次被其他类多继承. 比如class A: virtual T{} 这时T ...

  7. Codeforces 433 Div.2(A、B、C、D)

    A. Fraction 暴力遍历1-1000,取组成的真分数比值最大且分子分母gcd为1时更新答案 代码: #include <stdio.h> #include <algorith ...

  8. 架构-UML类图

    在UML 2.0的13种图形中,类图是使用频率最高的UML图之一.Martin Fowler在其著作<UML Distilled: A Brief Guide to the Standard O ...

  9. 牛客网暑期ACM多校训练营(第十场)D Rikka with Prefix Sum (数学)

    Rikka with Prefix Sum 题意: 给出一个数组a,一开始全为0,现在有三种操作: 1.  1 L R W,让区间[L,R]里面的数全都加上W: 2.  2     将a数组变为其前缀 ...

  10. python登录知乎

    #coding:utf-8 import requests import urllib3 import time class Zhihu: def __init__(self): self.login ...