Python Forum
List of pathlib.Paths Not Ordered As Same List of Same String Filenames
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List of pathlib.Paths Not Ordered As Same List of Same String Filenames
#9
All of the support that comes with pathlib is very well worth it.
I have been using it in applications and it saves a great deal of time.

Consider the following snippet of code:
 
            for key, entry in ffmt.items():
                filelist =
                filepath = self.fips.homepath.joinpath(*entry['location'])
                print(f'\n{filepath.resolve()}')
                if entry['filename'] == '..multi..':
                    filelist = [x for x in filepath.iterdir() if x.is_file()]
                else:
                    filelist.append(filepath)
                for file in filelist:
                    with file.open(encoding=encode) as f:
                        for rec in f:
                            fields = self.prepare_rec(rec.strip(), entry, gethead)
ffmt is a dictionary containing information on about twenty files. all located in separate
directories. Each of this dictionary's items nested dictionaries containing information pertaining
to each file. The sub dictionary, contains entries for file location, delimiter, and field information,
part of which is shown here:

                    'location': ['..', 'data', 'fipsCodes', 'GNIScodesForNamedPopulatedPlaces-etc',
                                 'CountryNames', 'geonames_20171023', 'Countries.txt'],
                    'delim': '    ',
from which filepath can be constructed.
This entire structure allows for a very simple interface that is easy to understand, and does oh so much!
A descriptor dictionary such as this can be easily stored in a json file, for use by all programs in the
application.

In my book, pathlib is well worth the effort required to be comfortable with. Take a look at the docs,
here
Reply


Messages In This Thread
RE: List of pathlib.Paths Not Ordered As Same List of Same String Filenames - by Larz60+ - Nov-12-2017, 12:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 3 506 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  Next/Prev file without loading all filenames WilliamKappler 9 937 Apr-12-2024, 05:13 AM
Last Post: Pedroski55
  Sample random, unique string pairs from a list without repetitions walterwhite 1 577 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  trouble reading string/module from excel as a list popular_dog 0 501 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,398 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  String to List question help James_Thomas 6 1,158 Sep-06-2023, 02:32 PM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,781 May-01-2023, 09:06 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 1,028 Feb-23-2023, 02:21 PM
Last Post: sparkt
  convert string to float in list jacklee26 6 2,105 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  Checking if a string contains all or any elements of a list k1llcod3 1 1,272 Jan-29-2023, 04:34 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020