码迷,mamicode.com
首页 > 编程语言 > 详细

python

时间:2015-05-24 06:30:50      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

import os

def rename_file():
    file_name_list=os.listdir(r"/Users/Lily/Documents/ASU1/CodePractise/prank")
    print(file_name_list)
    saved_path=os.getcwd()
    print("current working directory is"+saved_path)
    os.chdir(r"/Users/Lily/Documents/ASU1/CodePractise/prank")
    for file_name in file_name_list:
        os.rename(file_name, file_name.translate(None, "0123456789"))
    os.chdir(saved_path)

rename_file()

  os: Miscellaneous operating system interfaces

os.listdir(path):

Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order. It does not include the special entries ‘.‘ and ‘..‘ even if they are present in the directory.

Availability: Unix, Windows.

os.getcwd(): Return a string representing the current working directory.

os.chdir(path):Change the current working directory to path.

python string translate():

str.translate(table[, deletechars]);

Parameters

  • table -- You can use the maketrans() helper function in the string module to create a translation table.

  • deletechars -- The list of characters to be removed from the source string.

 

 

python

标签:

原文地址:http://www.cnblogs.com/lilyfindjobs/p/4525305.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!