简体   繁体   English

如何在Python中创建顺序文件名

[英]How To Create Sequential File Names In Python

I'm trying to create a script that will create sequential file names for images in a directory with leading zeros. 我正在尝试创建一个脚本,该脚本将为目录中的前导零创建图像的顺序文件名。 The current code I'm trying to use is: 我尝试使用的当前代码是:

####Take a picture.
filename='/home/pi/pictures/'print 'img_{0:05d}'.format(i)'.jpg'
self.shoot(filename=filename)

I'm getting a syntax error when running seen here below. 运行时出现以下语法错误。 http://prnt.sc/dhpf51 http://prnt.sc/dhpf51

As the screenshot, 作为屏幕截图,

filename='/home/pi/pictures/'print 'img_{0:05d}'.format(i)'.jpg'

is not correct syntaxt, you placed the print keyword between format string, you can just use format for creating the path string. 如果语法不正确,则将print关键字放在格式字符串之间,就可以使用format创建路径字符串。

filename='/home/pi/pictures/img_{0:05d}.jpg'.format(i)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM