It can get a file named myFile.txt, in which the content is:
file '/home/debian/1.flv'
file '/home/debian/2.flv'
file '/home/debian/3.flv'
file '/home/debian/4.flv'
file '/home/debian/5.flv'
Now I want to wrap it in Python
os.system("seq --format="file '/home/debian/%G.flv'" 5 > myFile.txt" )
File "<stdin>", line 1
os.system("seq --format="file '/home/debian/%G.flv'" 5 > myFile.txt" )
^
SyntaxError: invalid syntax
How to Wrap it in Python?
I do understand how to create the file in Python (kvivek)
It is my target to understand how to use complicated shell command in Python,
If the number of lines is a variable?
There is still a problem with
@Torxed escape character way
>>> i=7 >>> os.system("seq --format=\"file '/home/debian/%G.flv'\" %d > myFile.txt" %i ) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: float argument required, not str@ganachoco's triple quotes way
>>> os.system('''seq --format="file '/home/debian/%G.flv'" %d > myFile.txt" %i''') sh: 1: Syntax error: Unterminated quoted string
there are two staus to be considered, status 1: the variable is in the shell, we can do (I had verified the following tow shell commands)
root@debian:/home/debian# i=7
root@debian:/home/debian# seq --format="file '/home/debian/%G.flv'" $i > myFile.txt
How to wrap it in Python with os.system?
>>> os.system('i=7')
0
>>> os.system("seq --format=\"file '/home/debian/%G.flv'\" $i > myFile.txt")
seq: missing operand
Try `seq --help' for more information.
256
The variable is in the Python, now I want to call the shell command to put the variable from Python into the shell, how can I do?
>>> i=7 #in python prompt
>>> os.system("seq --format=\"file '/home/debian/%G.flv'\" `here i want to get value from python prompt` > myFile.txt")
os.system("seq --format=\"file '/home/debian/%G.flv'\" 5 > myFile.txt" )?