我正在尝试使用Shutil和Pathlib组合复制一个pdf文件,但是当我运行代码时,我遇到了错误信息"str object is not callable"。这个错误是由于使用str()将路径对象转换回字符串时导致的。请问为什么会出现这种情况?谢谢!
from pathlib import Path
from wand.image import Image as wandImage
import shutil
import sys
import os
def pdf2Jpeg(pdf_path):
pdf = pdf_path
jpg = pdf[:-3] + "jpg"
img = wandImage(filename=pdf)
img.save(filename=jpg)
src0 = Path(r"G:\Well Schematics\Well Histories\Merged")
dst0 = Path(r"G:\Well Schematics\Well Histories\Out")
if not dst0.exists():
dst0.mkdir()
pdfs = []
api = ''
name = ''
pnum = ''
imgs = []
for pdf in src0.iterdir():
pdfs.append(pdf)
for pdf in pdfs:
if not dst0.exists():
dst0.mkdir()
str = str(pdf.stem)
split = str.split('_')
api = split[0]
name = split[1]
pnum = split[2]
shutil.copy(str(pdf), str(dst0))
for file in dst0.iterdir():
newpdf = file
pdf2Jpeg(str(newpdf))
newpdf.unlink()
Path(path_here).as_posix()
来实现相同的功能。 - Prayson W. Danieldef path_object_to_str(obj): if isinstance(obj, pathlib.Path): return str(obj)
- Ilyas