【问题标题】:Bash :: display one output item per lineBash :: 每行显示一个输出项
【发布时间】:2016-03-29 03:38:43
【问题描述】:

我在终端运行这个python script.py,它输出urls的数组

rem_results = artist.search(name='rem')
rem = rem_results[0]
rem_blogs = rem.blogs
print 'Blogs about rem:', [blog.get('url') for blog in rem_blogs]

如何使用bash 命令输出每行一个项目

【问题讨论】:

    标签: python bash command-line


    【解决方案1】:

    为了将其保留在 Python 的上下文中,您不需要 bash 来执行您正在执行的操作,只需获取您正在迭代的任何内容,并在新行上使用 join,这样您的数据集合中的每个值都会被分开通过字符串中的新行:

    print('Blogs about rem: \n {}'.format('\n'.join(blog.get('url') for blog in rem_blogs)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-20
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 2015-10-24
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      相关资源
      最近更新 更多