确定文件名是否大于X个字符 [英] Determining if a filename is greater than X characters
问题描述
如何确定文件名是否大于某个数字
的字符然后将其截断为该数字?例如,一个名为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!!!
推荐答案
" hokiegal99" <豪******** @ hotmail.com>在消息中写道
news:93 ************************** @ posting.google.c om ...
"hokiegal99" <ho********@hotmail.com> wrote in message
news:93**************************@posting.google.c om...
如何确定文件名是否大于某个数字的字符数,然后将其截断为该数字?例如,名为XXXXXXXXX.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
http:// home。 rochester.rr.com/cyhome/
2003年8月2日星期六19:15,hokiegal99写道:
On Saturday 02 August 2003 19:15, hokiegal99 wrote:
我该怎么办?确定文件名是否大于特定数量的字符,然后将其截断为该数字?例如,名为XXXXXXXXX.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!!!
查看os.path模块和len( )内置。其中两个
应该能为您提供所需的一切。
look at the os.path module and also the len() builtin. The two of those
should give you everything you need.
Cy Edmunds写道:
Cy Edmunds wrote:
filename =" abcdefgh"
if len(filename)> 6:
filename = filename [:6]
打印文件名
abcdef
filename = "abcdefgh"
if len(filename) > 6:
filename = filename[:6]
print filename
abcdef
如果没有必要,只需使用
filename =文件名[:6]
- 图片
The if is not necessary, just use
filename=filename[:6]
--Irmen
这篇关于确定文件名是否大于X个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!