当前位置: 技术问答>linux和unix
python中如何去掉扩展名
来源: 互联网 发布时间:2016-08-31
本文导语: 我已经获得了文件的字符串,我如何去掉扩展名,包括点。 代码如下: import os # the file directory which you want deal with FileDir = "E:\develop\python\test" FileNameList = os.listdir(FileDir) EmotionList = [] PBList = [] PActionList =...
我已经获得了文件的字符串,我如何去掉扩展名,包括点。
代码如下:
import os
# the file directory which you want deal with
FileDir = "E:\develop\python\test"
FileNameList = os.listdir(FileDir)
EmotionList = []
PBList = []
PActionList = []
for FileName in FileNameList:
tmp1 = FileName.replace(" ","_")
print tmp1
tmp2 = tmp1.upper()
print tmp2
# 下面这行有问题,会把 如 xxxN.ANIM 变成xxx,后面的N也没了
tmp3 = tmp2.rstrip(".ANIM")
print tmp3
EmotionList.append("EMOTION_"+tmp3)
PBList.append("PB_"+tmp3)
PActionList.append("PACTION_"+tmp3)
print "n"
print "n"
print FileNameList
print EmotionList
print PBList
print PActionList
代码如下:
import os
# the file directory which you want deal with
FileDir = "E:\develop\python\test"
FileNameList = os.listdir(FileDir)
EmotionList = []
PBList = []
PActionList = []
for FileName in FileNameList:
tmp1 = FileName.replace(" ","_")
print tmp1
tmp2 = tmp1.upper()
print tmp2
# 下面这行有问题,会把 如 xxxN.ANIM 变成xxx,后面的N也没了
tmp3 = tmp2.rstrip(".ANIM")
print tmp3
EmotionList.append("EMOTION_"+tmp3)
PBList.append("PB_"+tmp3)
PActionList.append("PACTION_"+tmp3)
print "n"
print "n"
print FileNameList
print EmotionList
print PBList
print PActionList
|
找了个用python提取文件名的例子(去掉扩展名)
http://www.tt010.net/cms/show_article/1055.html
http://www.tt010.net/cms/show_article/1055.html