美文网首页Python
[Python]路径选择

[Python]路径选择

作者: _小老虎_ | 来源:发表于2018-11-28 11:41 被阅读9次
#!/bin/env python
#-*- encoding=utf8 -*-

import os,sys

if __name__=="__main__":
    print "__file__=%s" % __file__

    print "os.path.realpath(__file__)=%s" % os.path.realpath(__file__)

    print "os.path.dirname(os.path.realpath(__file__))=%s" % os.path.dirname(os.path.realpath(__file__))
  
    print "os.path.split(os.path.realpath(__file__))=%s" % os.path.split(os.path.realpath(__file__))[0]  

    print "os.path.abspath(__file__)=%s" % os.path.abspath(__file__)

    print "os.getcwd()=%s" % os.getcwd()

    print "sys.path[0]=%s" % sys.path[0]

    print "sys.argv[0]=%s" % sys.argv[0]

输出结果:
$ python ./python_test/test_path.py
__file__=./python_test/test_path.py
os.path.realpath(__file__)=./python_test\test_path.py
os.path.dirname(os.path.realpath(__file__))=./python_test
os.path.split(os.path.realpath(__file__))=./python_test
os.path.abspath(__file__)=./python_test\test_path.py
os.getcwd()=./
sys.path[0]=./python_test
sys.argv[0]=./python_test/test_path.py

引用:http://www.cnblogs.com/wind-wang/p/5822192.html

相关文章

  • [Python]路径选择

    引用:http://www.cnblogs.com/wind-wang/p/5822192.html

  • python3之requests安装(技术)

    在本地找到安装python的路径,选择scripts文件夹。

  • win10安装python

    win10在安装python注意的问题: python 3.8.3 要选择下面的,上面的无法选择安装路径。会导致在...

  • pip

    Python2 的路径查找命令:witch python Python3 的路径查找命令:which python...

  • pycharm python环境配置

    1、在python官网下载对应平台的python安装包,安装路径选择在c盘,新建一个python文件夹,方便后续查...

  • python 路径管理 sys, os, Pathlib

    python 获得文件所在绝对路径 获取文件当前工作目录路径(绝对路径) 获取上级路径 python Pathlib

  • windows下python的安装

    1.获取python安装包 来源:www.python.org 选择适合的版本下载并安装到默认路径,如C:\pyt...

  • python模块搜索路径的方式

    永久设置python搜索路径:PYTHONPATH、.pth文件、pycharm设置 临时设置python搜索路径...

  • Yaml 下载安装步骤

    1.下载路径:http://pyyaml.org/wiki/PyYAML 选择与python版本相对应的yaml...

  • ubuntu14.04+ros+anaconda+python

    ros写的python程序会依赖系统自带的python路径,但是装anaconda的时候会更改python的路径,...

网友评论

    本文标题:[Python]路径选择

    本文链接:https://www.haomeiwen.com/subject/injaqqtx.html