How do I parse a listing of files to get just the filenames in Python?

前端 未结 7 1519
一向
一向 2021-02-10 23:50

So lets say I\'m using Python\'s ftplib to retrieve a list of log files from an FTP server. How would I parse that list of files to get just the file names (the last column) ins

7条回答
  •  伪装坚强ぢ
    2021-02-11 00:27

    I believe it should work for you.

    file_name_list = [' '.join(each_file.split()).split()[-1] for each_file_detail in file_list_from_log]
    

    NOTES -

    1. Here I am making a assumption that you want the data in the program (as list), not on console.

    2. each_file_detail is each line that is being produced by the program.

    3. ' '.join(each_file.split())

    To replace multiple spaces by 1 space.

提交回复
热议问题