Udacity_Python程序算例之使用函数

2017-10-08  本文已影响7人  平平又无奇

让浏览器休息一段时间

import time
import webbrowser
total_breaks = 3
break_count = 0
print("This program started on " +time.ctime())
print("This program started on " +time.ctime())
while(break_count<total_breaks):
    time.sleep(10)
    webbrowser.open("http://www.jianshu.com/u/9b991ae9b682")
    break_count = break_count + 1

批量去掉文件名称中的数字

import os
def rename_files():
    file_list = os.listdir(r"D:\python\tut")
    saved_path = os.getcwd()
    print("Current Working Directory is" +saved_path)
    os.chdir(r"D:\python\tut")
    for file_name in file_list:
        os.rename(file_name,file_name.translate(None,"0123456789"))
    os.chdir(saved_path)
rename_files()
上一篇下一篇

猜你喜欢

热点阅读