【问题标题】:How to use variable's value in a Linux path to display contents?如何在 Linux 路径中使用变量的值来显示内容?
【发布时间】:2017-08-29 21:39:29
【问题描述】:

我一直坚持在 Linux 路径中使用 python 变量来显示内容,任何建议/指导/提示都会非常有帮助。

下面是我的python脚本:

#!/bin/python
import sys 
import os
db = sys.argv[1] 
type = sys.argv[2]
if type == "extract":
    path= 'extractfolder' 
elif type == "transform"
    path = 'transformfolder'

到目前为止我很成功,现在我想根据路径变量显示文件。我被困在这里:

os.system('hadoop fs -cat /bla/bla/%s/bla/%s/file.txt ' %db %path)

Error: Traceback (most recent call last):   File "./test.py", line 29,in <module>
       os.system('hadoop fs -cat /bla/bla/%s/bla/%s/file.txt' %db %path)

TypeError: not enough arguments for format string

研究完成:

我查了os.system也查到了subprocess,但是子进程包不是很好,没有得到任何提示。

【问题讨论】:

    标签: python


    【解决方案1】:

    TypeError: 格式字符串的参数不足

    格式字符串需要使用tuple/list/etc,例如:

    os.system('hadoop fs -cat /bla/bla/%s/bla/%s/file.txt ' % (db, path))
    

    【讨论】:

      猜你喜欢
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 2020-05-11
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      相关资源
      最近更新 更多