0

I'm experiencing problems with the string format conversion in Python (v2.6.5). I tried to set a string to format like this...

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

being path='home/john'

But I always get the same error

"Not enough arguments for format string"

I read the documentation, and this post Not enough arguments for format string but i can't find an appropriate answer.

Could someone help me?

Thanks in advance,

peixe

3 Answers 3

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

You need to have the format arguments at the end of the string. Not in between two strings.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, silly me...xDD I read somewhere that the format arguments should be set right after the string to format. I used to program in python in the past, but i didn't remember quite how the format string function work. Now I know. Thanks everyone! peixe
1

I think the problem is that you're filling in (path) in the middle of the string without performing an explicit string concatenation at the same time. The best solution is just to make it:

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

Comments

1

What you posted is actually a syntax error. Is something missing?

>>> 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

Let me suggest you use

os.system('/{path}/tabix -h -f ftp://<some_url> 4:387-388 > file.out'.format(path=path))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.