for 将 str 转换为 list 为什么?
我目前正在构建一个脚本来查找图像序列并将它们分组在一起。我的问题是当我获取文件名并对其运行“for in”时,它们会变成列表...为什么?这是我的代码:
import os, glob
path = r'C:\Users\manley\Desktop\testSeq'
for my_file in glob.glob( os.path.join(path, '*.jpg') ):
(dirName, fileName) = os.path.split(my_file)
(fileBaseName, fExt) = os.path.splitext(fileName)
#print fileName
pathLists = fileName
pathList1 = []
pathList2 = []
#print pathList
#print fileName
for fName in pathLists:
print fName
当 fName 打印时,文件名 = rightSide_020_30.0001.jpg
我得到每个字母的列表...... 如何获取 fName 以将 fileName 保留为 str?
I'm currently building a script to find image sequences and group them together.. my problem is when I get the file names and go to run a "for in" on them they turn into lists... why?? This is my code:
import os, glob
path = r'C:\Users\manley\Desktop\testSeq'
for my_file in glob.glob( os.path.join(path, '*.jpg') ):
(dirName, fileName) = os.path.split(my_file)
(fileBaseName, fExt) = os.path.splitext(fileName)
#print fileName
pathLists = fileName
pathList1 = []
pathList2 = []
#print pathList
#print fileName
for fName in pathLists:
print fName
The filename = rightSide_020_30.0001.jpg
when the fName prints I get a list of each letter...
How do I get the fName to perserve the fileName as a str?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该只这样做:
不需要更多代码。
You should only do this:
There's no need for more code.
你的代码对我来说有点不清楚,但在你的情况下,每个字母都会被打印,因为你这样做
你的
pathlist
是一个字符串。我认为你的意思是这样做:
Your code is a little unclear to me but in your case each letter is getting printed because your doing this
Your
pathlist
is a string.I think you meant to do this:
pathLists = fileName
这是一个字符串...代表一个文件名...当您for
遍历一个字符串时,它会产生每个字符...pathLists = fileName
which is a string... representing one file name... when youfor
over a string, it yields each character...