Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #91949 > unrolled thread
| Started by | David Aldrich <David.Aldrich@EMEA.NEC.COM> |
|---|---|
| First post | 2015-06-03 11:07 +0000 |
| Last post | 2015-06-03 11:07 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
RE: What sort of data structure to use? David Aldrich <David.Aldrich@EMEA.NEC.COM> - 2015-06-03 11:07 +0000
| From | David Aldrich <David.Aldrich@EMEA.NEC.COM> |
|---|---|
| Date | 2015-06-03 11:07 +0000 |
| Subject | RE: What sort of data structure to use? |
| Message-ID | <mailman.101.1433333945.13271.python-list@python.org> |
Thanks very much for all the answers given to my question. They help me to think about the problem pythonically.
Best regards
David
> -----Original Message-----
> From: Python-list [mailto:python-list-
> bounces+david.aldrich=emea.nec.com@python.org] On Behalf Of Peter
> Otten
> Sent: 03 June 2015 11:59
> To: python-list@python.org
> Subject: Re: What sort of data structure to use?
>
> David Aldrich wrote:
>
> > Hi
> >
> > I have written a Python utility that performs a certain activity on
> > some predefined sets of files. Here is the outline of what I have written:
> >
> > # File Set A
> > pathA = 'pathA'
> > fileListA = ['fileA1.txt', 'fileA2.txt']
> >
> > # File Set B
> > pathB = 'pathB'
> > fileListB = ['fileB1.txt', 'fileB2.txt', 'fileB3.txt']
> >
> > myFunc1(pathA, fileListA)
> > myFunc2(pathA, fileListA)
> >
> > myFunc1(pathB, fileListB)
> > myFunc2(pathB, fileListB)
> >
> > I want to add more file sets, so I really want to add the sets to a
> > list and iterate over the list, calling myFunc1 & myFunc2 for each item.
> >
> > My question is: what sort of data structure could I use to organise
> > this, given that I want to associate a set of files with each path and
> > that, for each set, there is an arbitrary number of files?
>
> I'd start simple and put (path, files) pairs into a list:
>
> path_files_pairs = [
> ("pathA", ["fileA1.txt", "fileA2.txt", ...]),
> ("pathB", ["fileB1.txt", ...]),
> ]
>
> for path, files in path_files_pairs:
> func1(path, files)
> func2(path, files)
>
> You can always add complications later:
>
> import glob
> import os
>
> class VirtualFileset:
> def __init__(self, folder, pattern):
> self.folder = folder
> self.pattern = pattern
> def __iter__(self):
> yield self.folder
> yield glob.glob(os.path.join(self.folder, self.pattern))
>
> path_files_pairs = [
> ("pathA", ["fileA1.txt", "fileA2.txt", ...]),
> ("pathB", ["fileB1.txt", ...]),
> VirtualFileset("pathC", "*.py"), # all python files in directory "pathC"
> ]
>
> for path, files in path_files_pairs:
> func1(path, files)
> func2(path, files)
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>
> Click
> https://www.mailcontrol.com/sr/51ZWmSF1P47GX2PQPOmvUmaGI8Tu3yGr
> Vrr5Tv1xM3UP2MNyoKSTyt0rIsjE4onM5MUvmWbo6fT3KeH4!zzvzA== to
> report this email as spam.
Back to top | Article view | comp.lang.python
csiph-web