欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python分离文件路径、文件名、和文件名后缀

程序员文章站 2022-06-12 13:46:17
...
  1 #!/usr/bin/python
  2 
  3 import os
  4 
  5 file_path = "/home/jenkins/test/state.java"
  6 (filepath, tempfilename) = os.path.split(file_path)
  7 (filename, extension) = os.path.splitext(tempfilename)
  8 
  9 print "  filepath=",filepath, "   tempfilename=",tempfilename , "  extension=",extension

 

结果:

  filepath= /home/jenkins/test    tempfilename= state.java   extension= .java

 

相关标签: python学习