I want to know why the loop wont stop hereHow can i make the attached pyunit python script search for tests in subfoldersWriting to file limitation on line lengthXLRD/Python: Encrypte Excel or make exceptionPython misinterpreting sys.argv[1] when called with * as filename?FileNotFoundError, os.getcwd() returns file name not a directoryReturning value returns NoneValue not displaying when called by functionCan't append a set of values from a ClassFor loop not stopping at the correct value in listPython script to find file in directory and create directory

How can "научись" mean "take it and keep trying"?

How did old MS-DOS games utilize various graphic cards?

Share calendar details request from manager's manager

How to construct an hbox with negative height?

What do abbreviations in movie scripts stand for?

Why didn't Voldemort recognize that Dumbledore was affected by his curse?

How to tell your grandparent to not come to fetch you with their car?

Are there downsides to using std::string as a buffer?

Can you see exclusive car models from other platforms when playing cross-platform?

Does Disney no longer produce hand-drawn cartoon films?

How to return a security deposit to a tenant

Overlapping String-Blocks

Are there any instruments that don't produce overtones?

C++ Arduino IDE receiving garbled `char` from function

Is it possible to 'live off the sea'

Why did the Herschel Space Telescope need helium coolant?

What is the `some` keyword in SwiftUI?

How to hide an urban landmark?

How to handle self harm scars on the arm in work environment?

Is using haveibeenpwned to validate password strength rational?

PhD - Well known professor or well known school?

Why would future John risk sending back a T-800 to save his younger self?

What makes Ada the language of choice for the ISS's safety-critical systems?

Is open-sourcing the code of a webapp not recommended?



I want to know why the loop wont stop here


How can i make the attached pyunit python script search for tests in subfoldersWriting to file limitation on line lengthXLRD/Python: Encrypte Excel or make exceptionPython misinterpreting sys.argv[1] when called with * as filename?FileNotFoundError, os.getcwd() returns file name not a directoryReturning value returns NoneValue not displaying when called by functionCan't append a set of values from a ClassFor loop not stopping at the correct value in listPython script to find file in directory and create directory






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I was trying to write a program that searches a nested directory and then returns a location of searched file.In order to nest the scan inside directories I called the function inside the function. I was successful in doing so as the program worked but when I wanted was to stop the searching when the first hit is done. The code is below. Can someone make me understand why he iteration won't stop.



search = sys.argv[2]

def find(loca,term):
count = 1
for file in os.listdir(loca):
if (count > 1):
break
try:
os.chdir(f'locafile')
newloca = loca + '\' + file
find(newloca,term)
except NotADirectoryError:
pass
except PermissionError:
pass

if(file == term):
print(file)
print(f"found the term at")
print(os.getcwd())
count += 1


find("E:/",search)









share|improve this question

















  • 1





    Please share the output of this program.

    – Artemis Fowl
    Mar 24 at 17:22











  • When you stepped through your program using a debugger, what did you see? Was it anything unexpected?

    – Roland Illig
    Mar 24 at 17:22











  • the output of this program will be as I told upside. The program scans the entire E directory and returns the search term which is provided in the console. All I want to know is why wont the iteration stop. Or am I doing something wrong

    – Dhiraz Gazurel
    Mar 24 at 17:25











  • No the program works fine. Only the loop is not stopping

    – Dhiraz Gazurel
    Mar 24 at 17:26

















1















I was trying to write a program that searches a nested directory and then returns a location of searched file.In order to nest the scan inside directories I called the function inside the function. I was successful in doing so as the program worked but when I wanted was to stop the searching when the first hit is done. The code is below. Can someone make me understand why he iteration won't stop.



search = sys.argv[2]

def find(loca,term):
count = 1
for file in os.listdir(loca):
if (count > 1):
break
try:
os.chdir(f'locafile')
newloca = loca + '\' + file
find(newloca,term)
except NotADirectoryError:
pass
except PermissionError:
pass

if(file == term):
print(file)
print(f"found the term at")
print(os.getcwd())
count += 1


find("E:/",search)









share|improve this question

















  • 1





    Please share the output of this program.

    – Artemis Fowl
    Mar 24 at 17:22











  • When you stepped through your program using a debugger, what did you see? Was it anything unexpected?

    – Roland Illig
    Mar 24 at 17:22











  • the output of this program will be as I told upside. The program scans the entire E directory and returns the search term which is provided in the console. All I want to know is why wont the iteration stop. Or am I doing something wrong

    – Dhiraz Gazurel
    Mar 24 at 17:25











  • No the program works fine. Only the loop is not stopping

    – Dhiraz Gazurel
    Mar 24 at 17:26













1












1








1








I was trying to write a program that searches a nested directory and then returns a location of searched file.In order to nest the scan inside directories I called the function inside the function. I was successful in doing so as the program worked but when I wanted was to stop the searching when the first hit is done. The code is below. Can someone make me understand why he iteration won't stop.



search = sys.argv[2]

def find(loca,term):
count = 1
for file in os.listdir(loca):
if (count > 1):
break
try:
os.chdir(f'locafile')
newloca = loca + '\' + file
find(newloca,term)
except NotADirectoryError:
pass
except PermissionError:
pass

if(file == term):
print(file)
print(f"found the term at")
print(os.getcwd())
count += 1


find("E:/",search)









share|improve this question














I was trying to write a program that searches a nested directory and then returns a location of searched file.In order to nest the scan inside directories I called the function inside the function. I was successful in doing so as the program worked but when I wanted was to stop the searching when the first hit is done. The code is below. Can someone make me understand why he iteration won't stop.



search = sys.argv[2]

def find(loca,term):
count = 1
for file in os.listdir(loca):
if (count > 1):
break
try:
os.chdir(f'locafile')
newloca = loca + '\' + file
find(newloca,term)
except NotADirectoryError:
pass
except PermissionError:
pass

if(file == term):
print(file)
print(f"found the term at")
print(os.getcwd())
count += 1


find("E:/",search)






python python-3.x






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 17:18









Dhiraz GazurelDhiraz Gazurel

59110




59110







  • 1





    Please share the output of this program.

    – Artemis Fowl
    Mar 24 at 17:22











  • When you stepped through your program using a debugger, what did you see? Was it anything unexpected?

    – Roland Illig
    Mar 24 at 17:22











  • the output of this program will be as I told upside. The program scans the entire E directory and returns the search term which is provided in the console. All I want to know is why wont the iteration stop. Or am I doing something wrong

    – Dhiraz Gazurel
    Mar 24 at 17:25











  • No the program works fine. Only the loop is not stopping

    – Dhiraz Gazurel
    Mar 24 at 17:26












  • 1





    Please share the output of this program.

    – Artemis Fowl
    Mar 24 at 17:22











  • When you stepped through your program using a debugger, what did you see? Was it anything unexpected?

    – Roland Illig
    Mar 24 at 17:22











  • the output of this program will be as I told upside. The program scans the entire E directory and returns the search term which is provided in the console. All I want to know is why wont the iteration stop. Or am I doing something wrong

    – Dhiraz Gazurel
    Mar 24 at 17:25











  • No the program works fine. Only the loop is not stopping

    – Dhiraz Gazurel
    Mar 24 at 17:26







1




1





Please share the output of this program.

– Artemis Fowl
Mar 24 at 17:22





Please share the output of this program.

– Artemis Fowl
Mar 24 at 17:22













When you stepped through your program using a debugger, what did you see? Was it anything unexpected?

– Roland Illig
Mar 24 at 17:22





When you stepped through your program using a debugger, what did you see? Was it anything unexpected?

– Roland Illig
Mar 24 at 17:22













the output of this program will be as I told upside. The program scans the entire E directory and returns the search term which is provided in the console. All I want to know is why wont the iteration stop. Or am I doing something wrong

– Dhiraz Gazurel
Mar 24 at 17:25





the output of this program will be as I told upside. The program scans the entire E directory and returns the search term which is provided in the console. All I want to know is why wont the iteration stop. Or am I doing something wrong

– Dhiraz Gazurel
Mar 24 at 17:25













No the program works fine. Only the loop is not stopping

– Dhiraz Gazurel
Mar 24 at 17:26





No the program works fine. Only the loop is not stopping

– Dhiraz Gazurel
Mar 24 at 17:26












1 Answer
1






active

oldest

votes


















0














Since you're using recursion, you need some way of signaling the parent when you find a hit. You can use return for that.



def find(loca,term):
count = 1
for file in os.listdir(loca):
if (count > 1):
break
try:
os.chdir(f'locafile')
newloca = loca + '\' + file
if find(newloca,term):
return 1
except NotADirectoryError:
pass
except PermissionError:
pass

if(file == term):
print(file)
print(f"found the term at")
print(os.getcwd())
count += 1
return 1





share|improve this answer























  • thnx your code works.. one more thing is this the efficient method to do this or there is something else more efficient

    – Dhiraz Gazurel
    Mar 24 at 18:06











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326420%2fi-want-to-know-why-the-loop-wont-stop-here%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Since you're using recursion, you need some way of signaling the parent when you find a hit. You can use return for that.



def find(loca,term):
count = 1
for file in os.listdir(loca):
if (count > 1):
break
try:
os.chdir(f'locafile')
newloca = loca + '\' + file
if find(newloca,term):
return 1
except NotADirectoryError:
pass
except PermissionError:
pass

if(file == term):
print(file)
print(f"found the term at")
print(os.getcwd())
count += 1
return 1





share|improve this answer























  • thnx your code works.. one more thing is this the efficient method to do this or there is something else more efficient

    – Dhiraz Gazurel
    Mar 24 at 18:06















0














Since you're using recursion, you need some way of signaling the parent when you find a hit. You can use return for that.



def find(loca,term):
count = 1
for file in os.listdir(loca):
if (count > 1):
break
try:
os.chdir(f'locafile')
newloca = loca + '\' + file
if find(newloca,term):
return 1
except NotADirectoryError:
pass
except PermissionError:
pass

if(file == term):
print(file)
print(f"found the term at")
print(os.getcwd())
count += 1
return 1





share|improve this answer























  • thnx your code works.. one more thing is this the efficient method to do this or there is something else more efficient

    – Dhiraz Gazurel
    Mar 24 at 18:06













0












0








0







Since you're using recursion, you need some way of signaling the parent when you find a hit. You can use return for that.



def find(loca,term):
count = 1
for file in os.listdir(loca):
if (count > 1):
break
try:
os.chdir(f'locafile')
newloca = loca + '\' + file
if find(newloca,term):
return 1
except NotADirectoryError:
pass
except PermissionError:
pass

if(file == term):
print(file)
print(f"found the term at")
print(os.getcwd())
count += 1
return 1





share|improve this answer













Since you're using recursion, you need some way of signaling the parent when you find a hit. You can use return for that.



def find(loca,term):
count = 1
for file in os.listdir(loca):
if (count > 1):
break
try:
os.chdir(f'locafile')
newloca = loca + '\' + file
if find(newloca,term):
return 1
except NotADirectoryError:
pass
except PermissionError:
pass

if(file == term):
print(file)
print(f"found the term at")
print(os.getcwd())
count += 1
return 1






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 24 at 17:42









John GordonJohn Gordon

11.9k51833




11.9k51833












  • thnx your code works.. one more thing is this the efficient method to do this or there is something else more efficient

    – Dhiraz Gazurel
    Mar 24 at 18:06

















  • thnx your code works.. one more thing is this the efficient method to do this or there is something else more efficient

    – Dhiraz Gazurel
    Mar 24 at 18:06
















thnx your code works.. one more thing is this the efficient method to do this or there is something else more efficient

– Dhiraz Gazurel
Mar 24 at 18:06





thnx your code works.. one more thing is this the efficient method to do this or there is something else more efficient

– Dhiraz Gazurel
Mar 24 at 18:06



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55326420%2fi-want-to-know-why-the-loop-wont-stop-here%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현