zoukankan      html  css  js  c++  java
  • 文件路径

    plot.py文件路径:/Users/yangfengjuan/jupyter/plot.py

    获取plot.py文件的绝对路径

    1 currentpath = os.path.dirname(os.path.realpath(__file__)) 
    2 运行结果:/Users/yangfengjuan/jupyter

    获取当前执行文件的路径

    1 currentpath = os.getcwd()
    2 运行结果:/Users/yangfengjuan/jupyter

    判断某个路径下是否存在某个文件

     1 os.path.exists()就是判断括号内的文件是否存在的意思,括号内可以是文件的路径
     2 os.path.exists('plot.py')
     3 运行结果:True

    创建目录

    在当前文件的同级文件夹plot下生成文件夹

     1 def get_content():
     2     temp_time = '2021-02-01'
     3     end_time = '2021-02-22'
     4     # 获取当前文件的绝对路径
     5     currpath = os.path.dirname(os.path.realpath(__file__))
     6     # 进入当前文件同级目录下的plot文件夹
     7     resultpath = currpath + os.sep + 'plot' + os.sep
     8     # plot文件夹下创建文件 2021-02-21_2021-02-28
     9     path = resultpath + str(temp_time).replace(' 00:00:00', '') + '~' + str(end_time).replace(' 00:00:00', '')
    10 
    11     # 判断plot文件夹下是否存在 拼接的文件夹
    12     if not os.path.exists(path):
    13         # 在plot文件夹下新建 拼接的文件夹
    14         os.mkdir(path)
    15     return path
    16 get_content()
    分享促进成长
  • 相关阅读:
    数据库pubs
    当前目录中查找特定类型的文件
    DBHelper,ADO直接操作数据库,扩展DataTable操作数据裤的方法
    行记录次序+等差数列
    面试的通用要求
    zoj_3367Connect them
    hdoj_4198Quick out of the Harbour
    Win32常见异常
    hdoj_1026Ignatius and the Princess I
    移动 II
  • 原文地址:https://www.cnblogs.com/hpzyang/p/14480378.html
Copyright © 2011-2022 走看看