os.path.walk -- Can You Limit Directories Returned?

2008-06-04 Thread Jeff Nyman
Greetings all.

I did some searching on this but I can't seem to find a specific
solution. I have code like this:

=
def walker1(arg, dirname, names):
DC_List.append((dirname,''))

os.path.walk('vcdcflx006\\Flex\\Sites', walker1, 0)
=

The Sites\ directory is set up like this:

Sites\
   Baltimore
   Birmingham
   

And so forth. Each of the city directories has directories under it as
well. The problem is that my code grabs every single directory that is
under the various city directories when what I really want it to do is
just grab the directories that are under Sites\ and that's it. I don't
want it to recurse down into the sub-directories of the cities.

Is there a way to do this? Or is os.path.walk not by best choice here?

Any help and/or advice would be appreciated.

- Jeff
--
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.walk -- Can You Limit Directories Returned?

2008-06-05 Thread Jeff Nyman
Thank you to everyone for your help.

Much appreciated. I now have a better understanding of how glob can be
used and I have a much better understanding of using the more
effective os.walk.


- Jeff
--
http://mail.python.org/mailman/listinfo/python-list


Creating A Tuple From A List, Adding To Tuple As You Do

2008-06-05 Thread Jeff Nyman
Greetings all.

The subject line of this thread is probably one of the worst ever. I
was trying to encapsulate what I am doing. Based on my new-found
knowledge from another thread, I'm able to get a list of directories
and they come to me in the form of a list. Here is an example:

from glob import glob
DC_List = glob('vcdcflx006\\Flex\\Sites\\*\\')
DC_List = ['Baltimore', 'Birmingham', 'Cincinnati', 'Cleveland',
LosAngeles']

(Each element in the DC_List is actually a full directory path, but I
shortened that in the interest of clarity.)

The problem is that I need to pass this list to a list control in a
wxWidgets application. In order to do that, I need to pass in a list
like this:

[ ('Baltimore', ''), ('Birmingham', ''), ('Cincinnati', ''),
('Cleveland', ''), ('LosAngeles', '') ]

In other words, each element in the list is a tuple that has an empty
second string. The problem I'm having is in converting my list above
to be of this type. I can't do append because that (logically) puts
everything at the end. I did try this:


for count in range(0, len(DC_List)):
DC_List.insert(count, '')


Here I was thinking I could insert a '' into the right place after
each entry in the list. That doesn't quite work. Does anyone have an
idea of a good approach here? (I did search on tuples and lists and
while I found a lot of information about both, I couldn't find a
solution that did what I'm discussing above.)

- Jeff
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating A Tuple From A List, Adding To Tuple As You Do

2008-06-05 Thread Jeff Nyman
Thanks to everyone who responded!

Yes, those solutions all work and do what I need. I'm also getting
much more familiar with how flexible Python is in terms of its
language. I think that's been the hardest challenge for me. I'm
usually finding I try to "overdo it" when coming up with solutions.

Once again, many thanks.

- Jeff
--
http://mail.python.org/mailman/listinfo/python-list