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:
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:
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
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