Python 获取当前脚本文件路径目录
2015-08-04 20:25
926 查看
# -*- coding: cp936 -*- import sys,os # 获取脚本文件的当前路径 def cur_file_dir(): # 获取脚本路径 path = sys.path[0] # 判断为脚本文件还是py2exe编译后的文件,如果是脚本文件,则返回的是脚本的目录,如果是py2exe编译后的文件,则返回的是编译后的文件路径 if os.path.isdir(path): return path elif os.path.isfile(path): return os.path.dirname(path) # 打印结果 print cur_file_dir()
相关文章推荐
- kafka-python实现获得kafka topic
- python常见模块命令(os/sys/platform)
- Python新手必备练习4---开发一个计算器程序
- 从Theano到Lasagne:基于Python的深度学习的框架和库
- python 中del 的用法
- python 中del 的用法
- Python2.7安装GeoIP
- Python read打印与print区别
- Windows下使用python-nmap库可能遇到的问题及解决方法(续)
- Windows下使用python-nmap库可能遇到的问题及解决方法(续)
- 使用python中logging模块记录日志
- Python中的变量
- google python class exercise
- python类实例访问规则
- python 报错 ImportError: No module named setuptools
- Python安装matplotlib所需要的软件以及问题的解决方法
- 【Python】阿里巴巴API签名生成
- Python3中目录操作
- Berkeley's SICP in python3(五)
- Python 学习笔记 集合