Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for loop in while loop
#1
import glob
import os
a = ['ACM','ACX','GSK']
i = 0
while i < len(a):
	print a[i]
	b=str(a[i])
	os.chdir('/ai2/data/dev/admin/inf/')
	for file in glob.glob('*b*'):
		print file
	i = i + 1
In the above code for loop is not working.
What is the mistake I did?
Please help
Reply
#2
What does mean "not working"? You've got an error? Doesn't print anything? Loop once?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
import glob
import os
base_path = '/ai2/data/dev/admin/inf/*{}*'
patterns = ['ACM','ACX','GSK']
for pattern in patterns:
    print pattern
    search_path =  base_path.format(pattern)
    for f in glob.glob(search_path):
        print f
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
Hi

The print statement in the while loop is printing the values but in the for loop it is not giving any thing
Reply
#5
you know that it is case-sensitive, right?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
Thanks Buran,

Its worked.

Thank you very much.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  for loop not executing Abendrot47 2 190 Apr-09-2024, 07:14 PM
Last Post: deanhystad
  Re Try loop for "net use..." failures tester_V 10 562 Mar-02-2024, 08:15 AM
Last Post: tester_V
  File loop curiously skipping files - FIXED mbk34 10 788 Feb-10-2024, 07:08 AM
Last Post: buran
  Optimise multiply for loop in Python KenBCN 4 480 Feb-06-2024, 06:48 PM
Last Post: Gribouillis
  Basic binary search algorithm - using a while loop Drone4four 1 352 Jan-22-2024, 06:34 PM
Last Post: deanhystad
  loop through csv format from weburl in python maddyad82 3 387 Jan-17-2024, 10:08 PM
Last Post: deanhystad
  Variable definitions inside loop / could be better? gugarciap 2 432 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  UART & I2C slow down a loop trix 4 607 Dec-28-2023, 05:14 PM
Last Post: trix
  Need an alternative to brute force optimization loop jmbonni 5 1,172 Dec-07-2023, 12:28 PM
Last Post: RockBlok
  Which GUI can have indefinite loop ? jst 20 1,715 Nov-16-2023, 10:23 PM
Last Post: jst

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020