首页 > 解决方案 > 如何将可读(r)添加到字符串?

问题描述

代码截图

我在使用文件路径时遇到问题,因为它包含\所以我必须添加r或交换\与 double \

问题是我想将 添加r到存储在变量中的字符串而不手动执行(我得到的变量包含带有 的路径input())。我怎么能那样做?

编辑:这是代码:

#The path of my directory
direc =str(input())
list = os.listdir(direc) #This gives me the name of all the files in my directory

cap = cv2.VideoCapture(the path of my directory \list[0]) #path of the file, this is where I have trouble
length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
print(length)

标签: python

解决方案


推荐阅读