How do I parse a listing of files to get just the

2020-06-04 19:21发布

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) inside a list? See the link above for example output.

7条回答
够拽才男人
2楼-- · 2020-06-04 20:21

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.

查看更多
登录 后发表回答