stat() got an unexpected keyword argument 'follow_symlinks'

Question:

Web search found links to bugs, I don’t write complicated code on Python, just want to confirm I understand syntax:

https://docs.python.org/3/library/pathlib.html

Path.stat(*, follow_symlinks=True)

But when I write Path(filepath).stat(follow_symlinks=False) I’m getting "stat() got an unexpected keyword argument ‘follow_symlinks’" error. lstat() in place of stat(follow_symlinks=False) does job done.

Python 3.8.5. TIA

Asked By: Alex Martian

||

Answers:

You’re reading it correctly. You just missed the footnote. From the page you linked

Changed in version 3.10: The follow_symlinks parameter was added.

So if you want to use that keyword argument, you need Python 3.10 or newer. Otherwise, as you’ve already figured out, just use lstat.

Answered By: Silvio Mayolo
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.