0

我在 Python (v2.6.5) 中遇到字符串格式转换问题。我试图将字符串设置为这样的格式...

os.system ('/%s/tabix' % (path) '-h -f ftp://<some_url> 4:387-388 > file.out' )

成为 path='home/john'

但我总是得到同样的错误

"Not enough arguments for format string"

我阅读了文档和这篇文章Not enough arguments for format string但我找不到合适的答案。

有人可以帮助我吗?

提前致谢,

佩谢

4

3 回答 3

6
os.system ('/%s/tabix -h -f ftp://<some_url> 4:387-388 > file.out' % (path))

您需要在字符串末尾有格式参数。不在两个字符串之间。

于 2012-03-26T17:10:44.617 回答
1

我认为问题在于您在字符串中间填充(路径)而没有同时执行显式字符串连接。最好的解决方案就是让它:

'/%s/tabix -h -f ftp://<some_url> 4:387-388 > file.out' % (path)
于 2012-03-26T17:13:19.590 回答
1

您发布的内容实际上是语法错误。有什么遗漏吗?

>>> import os
>>> path='home/john'
>>> os.system ('/%s/tabix' % (path) '-h -f ftp://<some_url> 4:387-388 > file.out' )
  File "<stdin>", line 1
    os.system ('/%s/tabix' % (path) '-h -f ftp://<some_url> 4:387-388 > file.out' )
                                                                                ^
SyntaxError: invalid syntax

让我建议你使用

os.system('/{path}/tabix -h -f ftp://<some_url> 4:387-388 > file.out'.format(path=path))
于 2012-03-26T17:29:10.550 回答