Python 如何将可读(r)添加到字符串?
我在使用我的文件路径时遇到问题,因为它包含Python 如何将可读(r)添加到字符串?,python,Python,我在使用我的文件路径时遇到问题,因为它包含\,因此我必须添加r,或者用双\交换\ 问题是我想将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
\
,因此我必须添加r
,或者用双\
交换\
问题是我想将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)
我认为您应该提供一个示例代码<代码>输入()函数不需要它。1。
r
是字符串文本的一段语法。字符串对象没有或没有r
,因此无法添加。2。如果你用input
输入一个字符串,你不应该逃避任何事情。谢谢你的编辑,顺便说一句,我是从你的代码新到这个网站的,现在还不清楚你到底在做什么或者你有什么问题。您在写我的目录路径的地方实际有什么代码\list[0]?