0

I am very new to python and programming.

I want to loop over these path:

/group/e000055/evtgen/00/all/00/  
/group/e000055/evtgen/00/all/01/    
/group/e000055/evtgen/00/all/02/

/group/e000055/evtgen/01/all/00/   
/group/e000055/evtgen/01/all/01/      
/group/e000055/evtgen/01/all/02/     

/group/e000055/evtgen/02/all/00/   
/group/e000055/evtgen/02/all/01/      
/group/e000055/evtgen/02/all/02/ 

After evtgen I have one stream start from 00 and and sub stream continues to 10 from 00.
Then another stream starts at 01 and again sub stream starts from 00 to 10.

I want to loop over all those path to submit jobs in python.

Could you please provide me a skeleton code for it.

Thanks in Advance.

Regards

1
  • Put a for loop inside a for loop. Commented Sep 18, 2020 at 9:38

3 Answers 3

1

Use something like this:

for i in range(10):
    for j in range(10):
        print('/group/e000055/evtgen/0%s/all/0%s/' % (i,j))

Output:

/group/e000055/evtgen/00/all/00/
/group/e000055/evtgen/00/all/01/
/group/e000055/evtgen/00/all/02/
...
...
/group/e000055/evtgen/09/all/08/
/group/e000055/evtgen/09/all/09/
Sign up to request clarification or add additional context in comments.

Comments

1

Are you creating these names, or do these paths already exist and you want to get a list of them? If the latter, the glob function is what you want.

>>> import glob
>>> print(glob.glob("/usr/lib/*/*.so"))
['/usr/lib/systemd/libsystemd-shared-245.so', '/usr/lib/tc/q_atm.so', '/usr/lib/tc/m_ipt.so', '/usr/lib/tc/m_xt.so', '/usr/lib/man-db/libmandb.so', '/usr/lib/man-db/libman.so', '/usr/lib/man-db/libman-2.9.1.so', '/usr/lib/man-db/libmandb-2.9.1.so',

Comments

0
path = '/group/e000055/evtgen/0'

for i in range(3):
    path1 = path + str(i) + '/all/0'
    for j in range(1, 4):
        print(path1 + str(j) + '/')

output:

/group/e000055/evtgen/00/all/01/
/group/e000055/evtgen/00/all/02/
/group/e000055/evtgen/00/all/03/
/group/e000055/evtgen/01/all/01/
/group/e000055/evtgen/01/all/02/
/group/e000055/evtgen/01/all/03/
/group/e000055/evtgen/02/all/01/
/group/e000055/evtgen/02/all/02/
/group/e000055/evtgen/02/all/03/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.