jinja2 incompatibility with paths created using pathlib

Skip to first unread message

Brad Reisfeld

Jun 27, 2018, 2:36:07 PM6/27/18
to pocoo-libs

jinja2 has been extremely useful in an application I am building.

As part of refactoring, I have been converting my application from using os.path to pathlib.

It appears that jinja2 (v2.10) is somewhat incompatible with paths created using pathlib.Path.

For example, if tdir is a pathlib Path object, the following generates an error:

jinja_environment = Environment(loader=FileSystemLoader(tdir), trim_blocks=False, lstrip_blocks=True)

where the bottom of the error traceback is 

    jinja_environment = Environment(loader=FileSystemLoader(tdir),
  File ".../python/anaconda3/lib/python3.6/site-packages/jinja2/loaders.py", line 163, in __init__
    self.searchpath = list(searchpath)
TypeError: 'PosixPath' object is not iterable

If I convert tdir to a string, things work fine.


Reply all
Reply to author
0 new messages