Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.listdir behaviour #51266

Closed
bigaddo mannequin opened this issue Sep 29, 2009 · 3 comments
Closed

os.listdir behaviour #51266

bigaddo mannequin opened this issue Sep 29, 2009 · 3 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@bigaddo
Copy link
Mannequin

bigaddo mannequin commented Sep 29, 2009

BPO 7017
Nosy @mdickinson

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:

assignee = None
closed_at = <Date 2009-09-30.00:14:07.701>
created_at = <Date 2009-09-29.07:07:29.613>
labels = ['type-bug']
title = 'os.listdir behaviour'
updated_at = <Date 2009-09-30.00:14:07.700>
user = 'https://bugs.python.org/bigaddo'

bugs.python.org fields:

activity = <Date 2009-09-30.00:14:07.700>
actor = 'bigaddo'
assignee = 'none'
closed = True
closed_date = <Date 2009-09-30.00:14:07.701>
closer = 'bigaddo'
components = ['None']
creation = <Date 2009-09-29.07:07:29.613>
creator = 'bigaddo'
dependencies = []
files = []
hgrepos = []
issue_num = 7017
keywords = []
message_count = 3.0
messages = ['93255', '93266', '93340']
nosy_count = 2.0
nosy_names = ['mark.dickinson', 'bigaddo']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue7017'
versions = ['Python 2.6']

@bigaddo
Copy link
Mannequin Author

bigaddo mannequin commented Sep 29, 2009

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)

for curFile in fileList:
   # print the file list to see if it is indeed growing
   print FileList
   fp = file(os.path.join(temporaryDirectory, "." + curFile), 'w')
   # write stuff
   fp.close()

Here is the output:

['a', 'b', 'c']
['a', 'b', 'c', '.a']
['a', 'b', 'c', '.a', '.b']
['a', 'b', 'c', '.a', '.b', '.c']

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.

@bigaddo bigaddo mannequin added the type-bug An unexpected behavior, bug, or error label Sep 29, 2009
@mdickinson
Copy link
Member

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'").

@bigaddo
Copy link
Mannequin Author

bigaddo mannequin commented Sep 30, 2009

I think I found my problem. Since I didn't *COPY* the array that I
created with os.listdir I was actually appending to it, my bad.

@bigaddo bigaddo mannequin closed this as completed Sep 30, 2009
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant