Home > Backend Development > Python Tutorial > How to use variables in python file storage path

How to use variables in python file storage path

爱喝马黛茶的安东尼
Release: 2019-06-18 11:15:40
Original
10093 people have browsed it

在python项目中,需要批量ocr图片后,批量生成同名的txt文件,存储文件需要使用路径,一般是path =r'd:\folder\filename.txt',使用变量怎么代替路径呢?

相关推荐:《python视频教程

How to use variables in python file storage path

步骤如下:

直接使用变量就可以了。

path=variable
Copy after login

How to use variables in python file storage path

因为r'()'符号的作用是使用原始字符串,它会改变引号内字符转义的规则。如果您只是从另一个变量中获取值,则不需要r写入字符串。

代码:

filelist=['test1.jpg','test2.jpg']
for filename in filelist:
   filenamev= 'D:\\baoan-nlt\\' + filename    
   savepath = filenamev[:-4]+'.txt'
Copy after login

How to use variables in python file storage path

The above is the detailed content of How to use variables in python file storage path. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template