1. 程式人生 > 實用技巧 >Python os.listdir方法程式碼示例

Python os.listdir方法程式碼示例

在下文中一共展示了Python os.listdir方法的程式碼示例,這些例子預設根據受歡迎程度排序。

示例1: help

# 需要匯入模組: import os [as 別名]
# 或者: from os import listdir [as 別名]
def help():
    print("""
    Usage:
    python weather-icons.py options
    options:
    loop
    image-file.png
    example:
    weather-icons.py loop
    weather-icons.py clear-day.png
    try one of the files from this list:
    {}
    """.format(', '.join(os.listdir(folder_path)))) 

示例2: loop

# 需要匯入模組: import os [as 別名]
# 或者: from os import listdir [as 別名]
def loop():
    print('Looping through all images in folder {}\n'
          'CRL+C to skip image'.format(folder_path))
    try:
        for img_file in os.listdir(folder_path):
            if img_file.endswith(icon_extension):
                print('Drawing image: {}'.format(folder_path + img_file))
                img = Image.open(folder_path + img_file)
                draw_animation(img)
            else:
                print('Not using this file, might be not an image: {}'.format(img_file))
    except KeyboardInterrupt:
        unicorn.off()
    unicorn.off()