0
from pathlib import Path
destination_file = "foo.txt"
current_dir = Path.cwd()
out_file = current_dir + destination_file

Throws the below error out_file = current_dir + destination_file TypeError: unsupported operand type(s) for +: 'WindowsPath' and 'str'

tdelaney
  • 73,364
  • 6
  • 83
  • 116
Prasanna K
  • 27
  • 1
  • 4
  • 8

1 Answers1

0

you recieving a Path object that cannot be concatenated to a string, instead do :

current_dir = Path.cwd() # WindowsPath('C:/full/path')
out_file  = current_dir.joinpath(destination_file) # WindowsPath('C:/full/path/dest_file.txt')
adir abargil
  • 5,495
  • 3
  • 19
  • 29
  • Thanks Adir so much. The outfile path is C:\Users\prasannakumaravel\PycharmProjects\SLU_DailyReport_Automation\Daily_report_23_Dec_2020.xlsx Traceback (most recent call last): File "C:\Users\prasannakumaravel\PycharmProjects\SLU_DailyReport_Automation\Testing.py", line 208, in refresh_excel_app() File "C:\Users\prasannakumaravel\PycharmProjects\SLU_DailyReport_Automation\Testing.py", line 199, in refresh_excel_app wb_7 = xlapp.workbooks.open(out_file) File ">", line 2, in open TypeError: must be real number, not WindowsPath – Prasanna K Dec 23 '20 at 07:10
  • The error is in a different place and a different issue, if you want you can open another question for it.. if the answer solved your issue please font forget to accept it – adir abargil Dec 23 '20 at 07:20