You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I iterate through a list created using os.listdir it seems to grow
as I create files in that directory. I want a static copy of the list of
files in the directory prior to me writing new files into it.
Here is my code:
fileList=os.listdir(temporaryDirectory)
forcurFileinfileList:
# print the file list to see if it is indeed growingprintFileListfp=file(os.path.join(temporaryDirectory, "."+curFile), 'w')
# write stufffp.close()
So the list is growing and eventually curFile iterates through the list
of files that were created. This behaviour was unwanted in my case and I
couldn't find any documentation about this.
What's 'FileList' in your code? (It's not the same as 'fileList', since
Python identifiers are case sensitive.)
What's 'temporaryDirectory'?
Please could you cut and paste an executable code snippet that exhibits
the problem, along with any other instructions necessary to reproduce
(e.g. "First create a directory 'tmp' containing files 'a', 'b' and 'c'").
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: