用自带的os模块或者分割split 路径

import os.path
filepath='k:/hello/test.py'
print(os.path.basename(filepath)[:-3])
l=filepath.split('/')[-1][:-3]
print(l)

- -

 注意python里获得的路径是/  而不是\

============= RESTART: C:\Users\AN\Desktop\learn Python\IDEL.py =============
test
test
>>>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
猜你喜欢
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案