繁体   English   中英

使列表打印成一行

[英]Make a list print in one line

我想知道如何使此代码一行打印。 我希望图像的完整路径在用空格隔开的一行中,但是我尝试了很多事情,由于某种原因,我似乎无法使其正常工作。 这是代码:

import os
import datetime as dt

now = dt.datetime.now()
ago = now-dt.timedelta(minutes=5)

for root, dirs,files in os.walk('C:/xxxx/xxxx/xxxx/xxxx/Images'):
    for fname in files:
        path = os.path.join(root, fname)
        st = os.stat(path)
        ctime = dt.datetime.fromtimestamp(st.st_ctime)
        if ctime > ago:
            print(path.replace('Images\\', 'Images/'))

您可以在打印时显式设置结束字符:

print(path.replace('Images\\', 'Images/'), end=' ')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM