python - 引用python中文件的下载

标签 python python-2.7

以下代码列出了具有 gfs.t*... 模式的文件,我还需要检查所有文件的大小是否超过 1000 (int(os.path.getsize(file))>1000)。但我只得到有关列表最后一个文件下载的结果。代码有什么问题吗?提前致谢

#! /opt/python2.7/bin/python2.7

from datetime import datetime
import os
import urllib
import shutil
import multiprocessing
import time
import glob

today = datetime.now()
if today.hour < 14:
   h = "00"
else:
   h = "12"
folder = "/home/Gribs/GFS0.25-p/gfs." + today.strftime('%Y%m%d')+ h

if not os.path.exists(folder):
    os.mkdir("/home/Gribs/GFS0.25-p/gfs." + today.strftime('%Y%m%d')+ h)

os.chdir(folder)
for file in glob.glob("gfs.t*"):
    print (file)

if(int(os.path.getsize(file))>1000):
    print (file + "downloaded right")
else:
    print (file + "not downloaded right")

最佳答案

试试这个,if else block 应该在 for 循环内缩进。

   for file in glob.glob("gfs.t*"):
        print (file)

        if(int(os.path.getsize(file))>1000):
            print (file + "downloaded right")
        else:
            print (file + "not downloaded right")

关于python - 引用python中文件的下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43425158/

相关文章:

python - 我想使用 TOTP 将我的响应发送到 API?

python - 对字典之间的值求和

python - Cython:缓冲区数据类型不匹配,预期为 'int',但得到了 Python 对象

python - 累积总和和结转 - 用 Pandas 矢量化

python - pip 安装 dynamic-dynamodb InsecurePlatformWarning

python - Django 模型 : how to return a default value in case of a non-existing foreign-key relationship?

python - 正确的 xpath 来卷起子项的文本

python - CSV 文件和字典

python-2.7 - 如何从pdf中提取特定标题下的文本?

python - 具有 n 个变量的迭代器的 n 个副本的笛卡尔积