The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by aulenbac]

Does os.path.walk work with Python 2.0 (#8, Oct 16 2000, 17:27:5smilie [MSC 32 bit
(Intel)] on win32 or am I missing something obvious?

The example given on page 130, second corrected printing works as expected on
a mac and on a sun (Python 1.5.2 (#1, Aug 18 2000, 13:10:32) [GCC 2.8.0] on
sunos5) but only returns the current working directory and the number of files
when I try it on an NT box. It does not appear to be recursively walking all
the directories. I have checked the "What's New" sections for both 2.0 and
2.1.

Any help would be greatly appreciated -- even if it is to tell me that I am
missing the obvious!

Thanks,
Steve

This is the code snippet I have been experimenting with:

import os
def printFunction(arg, directory, names):
print directory, len(names)

os.path.walk(os.getcwd(), printFunction, None)
import-bot (20211) [Avatar] Offline
#2
Re: os.path.walk
[Originally posted by daryl harms]

> Does os.path.walk work with Python 2.0 (#8, Oct 16 2000, 17:27:5smilie [MSC 32 bit
> (Intel)] on win32 or am I missing something obvious?
>
> The example given on page 130, second corrected printing works as expected on
> a mac and on a sun (Python 1.5.2 (#1, Aug 18 2000, 13:10:32) [GCC 2.8.0] on
> sunos5) but only returns the current working directory and the number of files
> when I try it on an NT box. It does not appear to be recursively walking all
> the directories. I have checked the "What's New" sections for both 2.0 and
> 2.1.
>
> Any help would be greatly appreciated -- even if it is to tell me that I am
> missing the obvious!
>
> Thanks,
> Steve
>
> This is the code snippet I have been experimenting with:
>
> import os
> def printFunction(arg, directory, names):
> print directory, len(names)
>
> os.path.walk(os.getcwd(), printFunction, None)

Hi Steve,

This code is working for me on NT4, i.e.:

Python 2.0 (#8, Oct 16 2000, 17:27:5smilie [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>> import os
>>> def printFunction(arg,directory,names):
print directory, len(names)


>>> os.path.walk(os.getcwd(), printFunction, None)
Csmilieython20 21
Csmilieython20DLLs 17
Csmilieython20Doc 14
...
...

I can't think of any obvious reasons you wouldn't see it moving into the
subdirectories.

The only thing I can suggest it to try it from scratch as above right after
firing up IDLE to ensure nothing is inadvertently changed in your environment
to interfere with it before you attempt it.

Daryl
import-bot (20211) [Avatar] Offline
#3
Re: os.path.walk
[Originally posted by aulenbac]

Hi Daryl,

Thanks for the help. I'll dig into it and see if I can figure out what is
happening on this machine. I'll let you know what I find.

Steve