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
  Returning data on button click by buttons created by a loop bradells 3 385 Apr-23-2025, 03:01 PM
Last Post: Pedroski55
  in c# create a loop counting from 0 to 5, consecutively Frankd 19 2,286 Apr-01-2025, 12:46 PM
Last Post: Frankd
  really new to python want to know how to do a loop pentopdmj 6 1,635 Mar-09-2025, 12:59 PM
Last Post: snippsat
  knowing for loop position in a list medic5678 4 719 Jan-31-2025, 04:19 PM
Last Post: perfringo
  Run this once instead of a loop, do I need the 'calibration' steps? duckredbeard 2 740 Jan-28-2025, 04:55 PM
Last Post: duckredbeard
  Error loop with Chatgpt sportak12 0 524 Jan-14-2025, 12:04 PM
Last Post: sportak12
  How to convert while loop to for loop in my code? tatahuft 4 855 Dec-21-2024, 07:59 AM
Last Post: snippsat
  How to get keep information in a loop ginod 4 911 Dec-11-2024, 01:32 AM
Last Post: deanhystad
  Regarding The For Loop Hudjefa 5 1,499 Nov-15-2024, 01:02 PM
Last Post: deanhystad
  For Loop beginner agoldav 2 738 Nov-05-2024, 12:51 AM
Last Post: agoldav

Forum Jump:

User Panel Messages

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