zoukankan      html  css  js  c++  java
  • python常用模块2

    os模块
    print(os.getcwd())#取当前工作目录
    print(os.chdir(r"e:yz_codeday2"))#更改当前目录
    print(os.mkdir("test1"))#创建文件夹
    print(os.makedirs(r"test1 est2"))#递归创建文件夹,父目录不存在时创建父目录
    # print(os.removedirs(r"test1 est2"))#递归删除空目录
    # print(os.rmdir("test1"))#删除指定的文件夹,只能删除空文件夹
    print(os.remove(r"E:yz_codeday4a.txt"))#删除文件
    # os.rename("test","test1")#重命名
    # print(os.sep)#当前操作系统的路径分隔符
    print(__file__)#代表当前文件
    print(os.path.abspath('bb.py'))#获取绝对路径
    # print(__file__)#代表当前文件
    # print(os.path.dirname)
    # print(os.path.dirname(os.path.dirname(__file__)))#获取父目录
    # print(os.path.exists("hhaaa"))#目录/文件是否存在
    # print(os.path.isfile("bb.py"))#判断是否是一个文件
    # print(os.path.isdir("/usr/local"))#是否是一个路径
    # print(os.path.join("root",'hehe','haha','a.log'))

    time&datetime模块
    time和datetime模块主要用于操作时间
    时间有三种表示方式,一种是时间戳、一种是格式化时间、一种是时间元组

    re模块
    re模块是正则表达式模块,用来匹配一些特定的字符串。
    常用的正则表达式符号

    常用的匹配语法

     

  • 相关阅读:
    HDU
    UVa——540Team Queue(STL练习map、queue数组的综合使用)
    NOJ——1659求值(log10取对数+floor取整数部分+可有可无的快速幂)
    NOJ——1658平方和(自然数平方和公式和取模法则)
    HDU——2723Electronic Document Security(STL map嵌套set做法)
    HDU——1982Kaitou Kid
    HDU——1073Online Judge(string类以及其对应函数)
    HDU——1062Text Reverse(水题string::find系列+reverse)
    HDU——1009FatMouse' Trade(贪心+结构体+排序)
    HDU——1799循环多少次(杨辉三角/动态规划/C(m,n)组合数)
  • 原文地址:https://www.cnblogs.com/lazy-cat-home/p/7072542.html
Copyright © 2011-2022 走看看