Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2228414
  • 博文数量: 287
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2130
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-31 14:30
个人简介

自己慢慢积累。

文章分类

全部博文(287)

分类: Python/Ruby

2017-10-17 17:15:11

1. 获取当前执行脚本的路径:

如果你在C:\test目录下执行python  getpath\getpath.py,那么:
os.getcwd()
输出“C:\test” 
sys.path[0]
输出“C:\test\getpath”。

这两个命令和 os.getcwd() 一样
print os.path.abspath(os.curdir)
print os.path.abspath('.')

2. 获取python所在的路径
import sys
sys.executable
输出:/usr/local/bin/python/
阅读(612) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~