Python_26_Udacity_Chawla_Python Foundation

总目录


课程页面:https://www.udacity.com/course/programming-foundations-with-python--ud036
授课教师:Kunal Chawla
如下内容包含课程笔记和自己的扩展折腾

打开网站

参见:https://pymotw.com/2/webbrowser/

# -*- coding: utf-8 -*-

import webbrowser
webbrowser.open('https://classroom.udacity.com/mex')

等待一段时间再运行

参见:http://stackoverflow.com/questions/15472707/make-python-program-wait

# -*- coding: utf-8 -*-

import webbrowser
import time
time.sleep(5) #5 seconds
webbrowser.open('https://classroom.udacity.com/mex')

当前时间

# -*- coding: utf-8 -*-

import webbrowser
import time
print "Current time", time.ctime()
for i in range(2):
    time.sleep(5) #5 seconds
    webbrowser.open('https://classroom.udacity.com/me')

The Python Standard Library

https://docs.python.org/2.7/library/index.html

修改文件名

# -*- coding: utf-8 -*-

import os

def rename_files():
    #(1) get file name from a folder
    file_list = os.listdir("/Users/yawenzhang/Downloads/prank")
    saved_path = os.getcwd()
    os.chdir("/Users/yawenzhang/Downloads/prank")
    #(2) for each file, rename filename
    for filename in file_list:
        os.rename(filename, filename.translate(None,'0123456789'))
    os.chdir(saved_path)
rename_files()

【内容待补全】

你可能感兴趣的:(Python_26_Udacity_Chawla_Python Foundation)