python,,import osd


import osdef 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 bypath. 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 topath.

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

相关内容

    暂无相关文章

评论关闭