9

I read that pathlib is the new Python way to deal with paths.

So I do:

with open(pic_name, 'wb') as image:
    image.write(download.content)
    image_path = Path(pic_name).resolve()
    return image_path

When I print image_path I get the full path to the image, but when I try to pass it to a function that uses ffmpeg to create a video file, I get:

TypeError: Can't convert 'PosixPath' object to str implicitly

I suspect this is because the object is Posix and the ffmpeg shell command expects a string.

In other cases I also got related error messages like

TypeError: 'PosixPath' object does not support indexing

or

TypeError: object of type 'PosixPath' has no len()

So how do you transform a Posix path to a string?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
xavier
  • 746
  • 2
  • 12
  • 22

1 Answers1

10

Python can't do it implicitly, but you can do it explicitly:

str(image_path)
glibdud
  • 7,550
  • 4
  • 27
  • 37