In the example from help(os.walk) it lists this:
from os.path import join, getsize
for root, dirs, files in walk('python/Lib/email'):
print root, "consumes",
print sum([getsize(join(ro ot, name)) for name in files]),
print "bytes in", len(files), "non-directory files"
if 'CVS' in dirs:
dirs.remove('CV S') # don't visit CVS directories
What I'm wondering is how does the "dirs.remove('C VS')" line prevent
os.walk from visiting that directory? how does the walk function know
what you do to the dirs variable? I tried looking at the code in
os.py but it wasn't clear to me there either.
Thanks,
Greg 2 4022 gr********@gmai l.com wrote:
In the example from help(os.walk) it lists this:
from os.path import join, getsize
for root, dirs, files in walk('python/Lib/email'):
print root, "consumes",
print sum([getsize(join(ro ot, name)) for name in files]),
print "bytes in", len(files), "non-directory files"
if 'CVS' in dirs:
dirs.remove('CV S') # don't visit CVS directories
What I'm wondering is how does the "dirs.remove('C VS')" line prevent
os.walk from visiting that directory? how does the walk function know
what you do to the dirs variable? I tried looking at the code in
os.py but it wasn't clear to me there either.
Simple: os.walk builds the list to contain all the subdirectories.
After giving you a chance to modify that list, ow.walk then goes through
the list (whatever contents it has at that point) and visits any
subdirectory.
I'd guess your trouble with understanding this has to do with wondering
how the modified list gets from your code back to os.walk. But in fact
they are not two separate lists, but one list, passed by reference from
os.walk into your code.
Gary Herron
Thanks,
Greg
On Jun 7, 5:13 pm, Gary Herron <gher...@island training.comwro te:
Simple: os.walk builds the list to contain all the subdirectories.
After giving you a chance to modify that list, ow.walk then goes through
the list (whatever contents it has at that point) and visits any
subdirectory.
I'd guess your trouble with understanding this has to do with wondering
how the modified list gets from your code back to os.walk. But in fact
they are not two separate lists, but one list, passed by reference from
os.walk into your code.
Thanks, that does make sense now.
-Greg This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jonas |
last post by:
This works fine in Win XP but does not work at all in Win 98.
Private WithEvents objIExplorer As InternetExplorer
I have to do it like this to get it to work in Win 98
Dim objIExplorer As InternetExplorer But then I cant see when a user exit my
objIExplorer and than an error will show up when I try to open a link in the
IE window that does not exist...
What can I do about this and way does it not work in win 98?
|
by: Miguel Cardenas |
last post by:
Hello list
For some strange reason `mysql_config --...` does not work. If try something
like
gcc -o progname `mysql_config --cflags` progname.c `mysql_config --libs`
(NOTE: "/usr/local/mysql/bin" is in the PATH var, mysql_config works when
invoked)
|
by: rick |
last post by:
The following basic script works fine in firefox by not in IE. Can anyone
spot the problem? In IE I can only delete the first line but not the lines
created by javascript. Also, look at the HTML code for the first line
(click the Table HTML button:)) you will fine that the code displayed is not
the same as
was written. "onChange" was changed to "onchange" etc. Please help.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">...
|
by: Generic Usenet Account |
last post by:
While I have a very good feel for how inlining works, I fail to see how
in the world inlining can work if the inlined function is not described
"in place" in a header file, but rather defined in a separate source
file (using the inline keyword), which gets linked in? Does inling
work at all in such cases? If it does, can someone kindly explain how
the compilers handle that? If it does not, is that documented
somewhere?
Thanks,
Gus
|
by: Harry Haller |
last post by:
Why does the following work:
// (1) Set new cookies
setcookie ("font_type", $type_sel, time()+3600);
setcookie ("font_size", $size_sel, time()+3600);
// (1) Get most recent cookie
$font_type = $_COOKIE;
$font_size = $_COOKIE;
if (isset($font_type) && isset($font_size))
echo "Found Cookies<br>\n";
| |
by: Jarod_24 |
last post by:
How does tabindex work in ASP .net pages
I dosen't seem to work quite like in regular forms. and there isn't any TabStop property either.
1 .How do you prevent a control form beign "tabbed". (hidden textboxes ect.)
2. How do get a control to get focus when the page is loaded (think username textfield on a loginpage)
3. Does the tab-order work just like in regular forms (1 ->2 -> 3 and so on?)
4. How does tabindex work with datagrid...
|
by: gsherp |
last post by:
I can get the Onclick event handler to work when I added a new row using insertRow. It doesn't work in IE or in FF
var cellarea = row.insertCell(2);
cellarea.style.backgroundColor = "#F4F4F4";
cellarea.align='center';
var area = document.createElement('input');
area.setAttribute('type', 'text');
area.setAttribute('name', 'area_' + iteration);
area.setAttribute('id', 'area_' + iteration);
...
|
by: DC |
last post by:
Hi,
why does this not work:
<asp:ImageButton
id="myButt"
runat="server"
OnCommand="myButt_kick"
ImageUrl="<% =GetMyButtUrl() %>"
</asp:ImageButton>
|
by: Pat |
last post by:
Hi ASP Gurus,
Please help me.
Autocomplete works fine when the control does not have the focus when the
page load.
But when I put the focus on page load, then autocomplete does not work.
I even tried javascript pageload code, but with no success.
<script language ="javascript" type ="text/javascript" >
function focusIt() {
//alert('test');
var mytext =
|
by: sva0008 |
last post by:
i have a auto suggest script that does not work in firefox , works great on IE.
/*******************************************************
AutoSuggest - a javascript automatic text input completion component
Copyright (C) 2005 Joe Kepley, The Sling & Rock Design Group, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |