本文摘自php中文网,作者(*-*)浩,侵删。
Python获取当前文件名可以通过__file__或者sys.argv[0],下面以test.py文件为例.test.py:(推荐学习:Python视频教程)
1 2 3 4 5 6 7 8 9 10 11 12 13 | # -*- coding: utf-8 -*-
# test.py
import sys
import os
# 绝对路径
print ( __file__ )
print (sys.argv[0])
# 文件名
print (os.path. basename ( __file__ ))
print (os.path. basename (sys.argv[0]))
|
阅读剩余部分
相关阅读 >>
基于matplotlib Python实现正弦信号的时域波形和频谱图示例
Python字符串连接的几种方式总结
Python属于什么类型语言
如何使用Python实现调查问卷的自动填写
Python中where()函数的用法详解
Python ide修改背景颜色的教程
Python怎么爬取ajax
Python能做什么?是什么?
Python格式化输出%s和%d
Python解析json的实例分享
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python 怎么获取文件名