I am trying to create some file paths to create new csv file in the target folder.
My code is as follows.
#The original path.
path_1=r'C:\Users\hh\OneDrive - Technology, Inc\IE'
#Creating the new path with the original path.
folder_name='New Folder'
x='\\'
path_2='r'+"'"+path_1+x+folder_name+"'"
#Creating the other new path with csv file name.
import csv
csv_name='r'+"'"+path_1+x+folder_name+x+'New File.csv'+"'"
#Creating a new csv file in the target folder.
with open(csv_name, 'wb') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
I had checked the paths I created many times, and didn’t find anything wrong. However, It keeps showing the error as follows.
[Errno 22] Invalid argument: "r'C:\\Users\\hh\\OneDrive - Technology, Inc\\IE\\New Folder\\New File.csv'"
Please help me find out what did I do wrong.
>Solution :
Remove the ‘r’ +
And then, if you want concatenate file path, use os.path.join() like this
import os
folder_name = r"C:/test/today"
name = "test.csv"
print(os.path.join(folder_name, name)) # C:/test/today/test.csv