【问题标题】:How to Strip Python Output如何剥离 Python 输出
【发布时间】:2011-12-16 03:41:57
【问题描述】:

我想剥离platform.linux_distribution()

输出是元组('Ubuntu', '11.10', 'oneiric'),但我想将其显示为"Ubuntu 11.10 oneriric"

.group(1) 不工作。

【问题讨论】:

  • 这个问题不清楚。您是否只是想将元组格式化为字符串?

标签: python linux linux-distro


【解决方案1】:

这个怎么样:

" ".join(platform.linux_distribution())

【讨论】:

    【解决方案2】:

    怎么样:

    ' '.join(platform.linux_distribution())
    

    我在 Mac 上,所以我没有 platform.linux_distribution(),但它看起来应该返回一个数组。

    【讨论】:

      【解决方案3】:

      你正在寻找" ".join():

      >>> import platform
      >>> platform.linux_distribution()
      ('Ubuntu', '11.04', 'natty')
      >>> " ".join(platform.linux_distribution())
      'Ubuntu 11.04 natty'
      >>> 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-06-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多