(1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如:
 
             python d:/pythonSrc/test/test.py
 
             那么将输出 d:/pythonSrc/test
 
     (2).当"print os.path.dirname(__file__)"所在脚本是以相对路径被运行的, 那么将输出空目录,比如:
 
             python test.py
 
             那么将输出空字符串

转: Python中的os.path.dirname(__file__)的更多相关文章

  1. python中的os.path.dirname(__file__)的使用

    在编程时,我们要获取当前文件所在的路径,以适合所有的工程,建立相对路径. python的os.path.dirname(__file__)非常好用,建议大家使用: import os FILE = o ...

  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. Android UI-仿微信底部导航栏布局

    现在App基本的标配除了侧滑菜单,还有一个就是底部导航栏,常见的聊天工具QQ,微信,购物App都有底部导航栏,用户可以随便切换看不同的内容,说是情怀也好,用户体验也罢.我们开发的主要的还是讲的是如何如 ...

  2. Largest Rectangle in Histogram leetcode java

    题目: Given n non-negative integers representing the histogram's bar height where the width of each ba ...

  3. Sort List leetcode java

    题目: Sort a linked list in O(n log n) time using constant space complexity. 题解: 考虑到要求用O(nlogn)的时间复杂度和 ...

  4. 【转】gcc选项

    http://zodiac1111.github.io/blog/config-gcc-warning/

  5. jquery解析XML及获取XML节点名称

    ).tagName $().tagName [].tagName[] $(].tagName context.nodeName $(this).context.nodeName function ge ...

  6. ZOJ 2319 Beautiful People

    LIS.先按S降序升序再按B降序排序(如果B不按降序排序的话就会覆盖掉正解),然后再对B用O(nlog(n))的LIS求解就可以了.用d数组标记每个元素在上升序列中的位置,然后根据d倒着找id就可以了 ...

  7. iOS new 和 alloc的区别

    一般如果只是 alloc init 那么 用new 是一样的 SomeObject*myObject =[[SomeObject alloc] init]; SomeObject*myObject = ...

  8. android实现六边形等不规则布局

    在去年广告机项目中,UI设计出一个比较华丽的UI,但是对于我来说无从下手,我试过view的叠加并设置外边距实现,虽然勉强可以实现,但是获取单击焦点是有很多问题: 效果图如下: 最后只有另外想办法:我对 ...

  9. 【.NET特供-第三季】ASP.NET MVC系列:传统WebForm站点和MVC站点执行机制对照

    本文以图形化的方式,从'执行机制'方面对照传统WebForm站点和MVC站点. 请參看下面图形: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb2 ...

  10. 使用web_url注意Resource的选项

    在使用web_url的时候,一定注意Resource的使用,一般最好使用Resource=0,如果使用Resource=1,那么一定要修改配置. Resource Attribute If Resou ...