0

How do I convert a for loop from bash to python

for example: for f in *; do cd $f git clone <> cd ../ done;

23rd Sep 2016, 4:39 AM
divya
3 ответов
+ 1
I don't have python in front of me (just docs and Google) so conceptually (until someone answers, or this helps you think about the problem): for f in * .... a list of filesystem iterables. To load an iterable list in python you can use 'dir' or 'os.walk'. You don't need to 'cd' in python, just iterate/walk. To shell out and execute 'git', you can use GitPython (https://github.com/gitpython-developers/GitPython) or 'subprocess.POpen'.
23rd Sep 2016, 4:00 PM
Kirk Schafer
Kirk Schafer - avatar
0
thank you. Will try that
23rd Sep 2016, 8:38 PM
divya
0
I am totally stuck here.. I am not sure how to change directory and run a command in that directory, exit and move on to the next directory in a loop. can you please help
26th Sep 2016, 6:12 PM
divya