在编程时,我们要获取当前文件所在的路径,以适合所有的工程,建立相对路径。

python的os.path.dirname(__file__)非常好用,建议大家使用:

 import os
FILE = os.path.join(os.path.dirname(__file__), 'models/lenet5')
print(FILE)

输出:

python中的os.path.dirname(__file__)的使用的更多相关文章

  1. 转: Python中的os.path.dirname(__file__)

     (1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如:                 ...

  2. python中的os.path.dirname与os.path.dirname(__file__)的用法

    python中的os.path.dirname的用法 os.path.dirname(path) 语法:os.path.dirname(path) 功能:去掉文件名,返回目录 如: print(os. ...

  3. os.path.dirname(__file__)使用、Python os.path.abspath(__file__)使用

    python中的os.path.dirname(__file__)的使用 - CSDN博客https://blog.csdn.net/u011760056/article/details/469698 ...

  4. python中os.path.dirname(__file__) 命令行 参数没有绝对路径导致数据库找不到

    (1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: python d:/python ...

  5. Python os.path.dirname(__file__) 与 Python os.path.abspath(__file__) 与 os.system() 函数

    Python  os.path.dirname(__file__) 与 Python os.path.abspath(__file__) 的区别 os.path.abspath(__file__)返回 ...

  6. Python os.path.dirname(__file__) os.path.join(str,str)

    Python os.path.dirname(__file__) Python os.path.join(str,str)   (1).当"print os.path.dirname(__f ...

  7. Python——os.path.dirname(__file__) 与 os.path.join(str,str)

    Python os.path.dirname(__file__) Python os.path.join(str,str)   (1).当"print os.path.dirname(__f ...

  8. os.path.dirname(__file__)使用

    os.path.dirname(__file__)使用 该测试脚本所在的位置:D:\第1层\第2层\第3层\第4层\第5层\test11.py test11.py import os #该文件所在位置 ...

  9. os.path.dirname(__file__)

    os.path.dirname(__file__) 返回脚本的路径 描述: 必须实际存在的.py文件,如果直接在命令行执行,则会引发异常NameError: name 'file' is not de ...

随机推荐

  1. 【AaronYang第一讲】ASP.NET MVC企业开发的基本环境[资源服务器概念]

    学完了ASP.NET MVC4 IN ACTION 六波以后 企业开发演习 标签:AaronYang  茗洋  EasyUI1.3.4   ASP.NET MVC 3 本篇博客地址:http://ww ...

  2. Effective Java 第三版——48. 谨慎使用流并行

    Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...

  3. Android查询不到电话号码解决方法

    貌似联系人有三个数据库,且不同步,另外也有可能是版本问题. 解决方案:https://github.com/codinguser/android_contact_picker 接下来会对其进行一些改造 ...

  4. TWELP™ Vocoder

    TWELP™ Vocoder   DSP Innovations Inc. (DSPINI) announces new class of proprietary vocoders for wide ...

  5. Push to origin/master was rejected (Git提交错误)(转)

    [问题描述] 在使用Git Push代码的时候,会出现 Push to origin/master was rejected 的错误提示. 在第一次提交到代码仓库的时候非常容易出现,因为初始化的仓库和 ...

  6. Centos 6.4 安装dnsmasq

    1 下载源码 wget http://www.thekelleys.org.uk/dnsmasq/dnsmasq-2.45.tar.gz cp dnsmasq-2.45.tar.gz /usr/src ...

  7. RR算法 调度

    RR算法是使用非常广泛的一种调度算法. 首先将所有就绪的队列按FCFS策略排成一个就绪队列,然后系统设置一定的时间片,每次给队首作业分配时间片.如果此作业运行结束,即使时间片没用完,立刻从队列中去除此 ...

  8. 教程:SpagoBI开源商业智能之XML Template 图表模板

    SpagoBI offers a variety of widgets' examples realized with the Highcharts library, that can be divi ...

  9. 阿里云ECS服务器主机安装多个网站

    web|服务器|站点 Windows 2000 Server安装成功后,一般会启动一个默认的Web站点,为整个网络提供Internet服务.在中小型局域网中,服务器往往只有一台,但是一个Web站点显然 ...

  10. java对象与map对象相互转换

    /** * 使用org.apache.commons.beanutils进行转换 */ class A { public static Object mapToObject(Map<String ...