Using python to run bash commands and get Output
Question: I want to download videos through Youtube-he. So,I wrote program but it isn't
working.The code is

    
    
    import os
    l=["sets","relation_and_functions","Trig","Complex_Quad","Linear_inequalities","Permutation","Binomial","Sequence","Straight","conic","Three_d","Limit_Derivative","Stats","Probability","Math_reasoning"]
    r=["https://www.youtube.com/playlist?list=PLD5EF274490578CC4","https://www.youtube.com/playlist?list=PL548FAD237A4B6D2E","https://www.youtube.com/playlist?list=PL42123C3873AED16F","https://www.youtube.com/playlist?list=PL880E3116D67E42FD","https://www.youtube.com/playlist?list=PLC5D1199BAE318878","https://www.youtube.com/playlist?list=PL812413BD6B55AA6E","https://www.youtube.com/playlist?list=PL78FAFAFA8496BCE1","https://www.youtube.com/playlist?list=PL6F57725E2DA8B557","https://www.youtube.com/playlist?list=PLA243228EA688A835","https://www.youtube.com/playlist?list=PL41B47FB4E23B392A","https://www.youtube.com/playlist?list=PLa2X112u1cdjdl-dsLJC1HaCeGrOarZZz","https://www.youtube.com/playlist?list=PLF6640F0A9F39F7BA","https://www.youtube.com/playlist?list=PL6FDE1AB3AE32E614","https://www.youtube.com/playlist?list=PL7FF5AD1CFF0981E5","https://www.youtube.com/playlist?list=PL13B63CD6FFAB9EA8"]
    for i in range(len(l)):
        a=l[i]
        b=r[i]
        os.system("mkdir a")
        os.chdir("a")
        os.system("youtube-dl b")
    


Answer: You need to pass the actual variables, not a string. You should also use the
subprocess module in particular
[check_call](https://docs.python.org/2/library/subprocess.html#subprocess.check_call):

    
    
    l =["sets","relation_and_functions","Trig","Complex_Quad","Linear_inequalities","Permutation","Binomial","Sequence","Straight","conic","Three_d","Limit_Derivative","Stats","Probability","Math_reasoning"]
    r=["https://www.youtube.com/playlist?list=PLD5EF274490578CC4","https://www.youtube.com/playlist?list=PL548FAD237A4B6D2E","https://www.youtube.com/playlist?list=PL42123C3873AED16F","https://www.youtube.com/playlist?list=PL880E3116D67E42FD","https://www.youtube.com/playlist?list=PLC5D1199BAE318878","https://www.youtube.com/playlist?list=PL812413BD6B55AA6E","https://www.youtube.com/playlist?list=PL78FAFAFA8496BCE1","https://www.youtube.com/playlist?list=PL6F57725E2DA8B557","https://www.youtube.com/playlist?list=PLA243228EA688A835","https://www.youtube.com/playlist?list=PL41B47FB4E23B392A","https://www.youtube.com/playlist?list=PLa2X112u1cdjdl-dsLJC1HaCeGrOarZZz","https://www.youtube.com/playlist?list=PLF6640F0A9F39F7BA","https://www.youtube.com/playlist?list=PL6FDE1AB3AE32E614","https://www.youtube.com/playlist?list=PL7FF5AD1CFF0981E5","https://www.youtube.com/playlist?list=PL13B63CD6FFAB9EA8"]
    
    from subprocess import check_call
    
    for direc, url in zip(l, r):
         check_call(["mkdir", direc])
         check_call(["youtube-dl", ele2],cwd=direc)
    

`zip(l, r)` zips the corresponding elements from each list so we simply unpack
the pairs in the loop. `cwd=direc` will set the directory to download the file
to.

