Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将可读(r)添加到字符串?_Python - Fatal编程技术网

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]?