Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28690
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-09-07 07:28 -0700 |
| References | <feae1d5a-c477-4e21-8136-c14e38672cb9@googlegroups.com> |
| Message-ID | <c93f63c5-e34f-4747-ab11-c18f9252e997@googlegroups.com> (permalink) |
| Subject | Re: Function for examine content of directory |
| From | Tigerstyle <laddosingh@gmail.com> |
Ok I'm now totally stuck.
This is the code:
---
import os
from collections import Counter
path = ":c\\mypath\dir"
dirs = os.listdir( path )
filenames = {"this.txt", "that.txt", "the_other.txt","this.doc","that.doc","this.pdf","first.txt","that.pdf"}
extensions = []
for filename in filenames:
f = open(filename, "w")
f.write("Some text\n")
f.close()
name , ext = os.path.splitext(f.name)
extensions.append(ext)
# This would print all the files and directories
for file in dirs:
print(file)
for ext, count in Counter(extensions).items():
print("Count for %s: " % ext, count)
---
I need to make this module into a function and write a separate module to verify by testing that the function gives correct results.
Help and pointers are much appreciated.
T
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Function for examine content of directory Tigerstyle <laddosingh@gmail.com> - 2012-09-06 07:56 -0700
Re: Function for examine content of directory Ian Foote <ian@feete.org> - 2012-09-06 16:06 +0100
Re: Function for examine content of directory MRAB <python@mrabarnett.plus.com> - 2012-09-06 16:20 +0100
Re: Function for examine content of directory Tigerstyle <laddosingh@gmail.com> - 2012-09-06 13:26 -0700
Re: Function for examine content of directory Tigerstyle <laddosingh@gmail.com> - 2012-09-06 13:26 -0700
Re: Function for examine content of directory Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-06 17:26 -0400
Re: Function for examine content of directory Chris Angelico <rosuav@gmail.com> - 2012-09-07 07:48 +1000
Re: Function for examine content of directory Tigerstyle <laddosingh@gmail.com> - 2012-09-07 07:23 -0700
Re: Function for examine content of directory Tigerstyle <laddosingh@gmail.com> - 2012-09-07 07:28 -0700
Re: Function for examine content of directory Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-07 15:21 -0400
csiph-web