【问题标题】:Import a csv file which was created at specific time instant in Python导入在 Python 中特定时间创建的 csv 文件
【发布时间】:2020-12-24 17:21:39
【问题描述】:

我在特定目录中有 csv 文件,其中一些随机名称是在某个时刻创建的。例如:

在第一天 11:00 时创建的 File.csv

Random.csv 创建于第一天 11:15 时

Data.csv 创建于第二天 12:00 时

在第 3 天 13:10 时创建的 Log.csv

我需要导入在第一天 11:10-11:30 之间创建的文件(对应于“Random.csv”)

有人可以告诉我我们如何在 Python 中解决这个问题吗?

【问题讨论】:

    标签: python python-3.x csv


    【解决方案1】:
    import os, time, datetime
    for file in os.listdir():
        if file.endswith(".csv"):
            d = datetime.datetime.strptime(time.ctime(os.path.getctime(file)), "%a %b %d %H:%M:%S %Y")
            if d.day == 1 and d.hour == 11 and d.minute >= 10 and d.minute <= 30:
                print(file) #load your file here
    

    【讨论】:

    • 更简单的datetime.datetime.fromtimestamp(os.path.getctime(file))
    • 感谢@Tanmay 的建议
    猜你喜欢
    • 2015-01-12
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    • 2021-05-17
    • 2017-08-05
    • 1970-01-01
    • 2017-02-18
    • 2019-05-31
    相关资源
    最近更新 更多