问题描述
如何确定文件名是否大于某个数字
的字符然后将其截断为该数字?例如,一个名为XXXXXXXXX.txt的文件名为XXXXXXXX.txt将成为XXXXXX
fname = files
如果fname [0]> 6
打印fname [0]
谢谢!!!
How would I determine if a filename is greater than a certain number
of characters and then truncate it to that number? For example a file
named XXXXXXXXX.txt would become XXXXXX
fname = files
if fname[0] > 6
print fname[0]
Thanks!!!
推荐答案
filename =" abcdefgh"
if len(filename)> 6:
filename =文件名[:6]
打印文件名
abcdef
-
Cy
查看os.path模块和len( )内置。其中两个
应该能为您提供所需的一切。
look at the os.path module and also the len() builtin. The two of those
should give you everything you need.
如果没有必要,只需使用
filename =文件名[:6]
- 图片
The if is not necessary, just use
filename=filename[:6]
--Irmen
这篇关于确定文件名是否大于X个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!