•        Python : 3.7.0
  •          OS : Ubuntu 18.04.1 LTS
  •         IDE : PyCharm 2018.2.4
  •       Conda : 4.5.11
  •    typesetting : Markdown

code

  1. """
  2. @Author : 行初心
  3. @Date : 18-10-2
  4. @Blog : www.cnblogs.com/xingchuxin
  5. @Gitee : gitee.com/zhichengjiu
  6. """
  7. import os
  8. def main():
  9. # 操作字符串,而不是操作真的路径
  10. file_path = '/home/coder/PycharmProjects/base/demo.py'
  11. # 去除路径,返回所在文件夹的路径
  12. print(os.path.dirname(file_path))
  13. if __name__ == '__main__':
  14. main()

result

  1. /home/coder/anaconda3/envs/py37/bin/python /home/coder/PycharmProjects/base/demo.py
  2. /home/coder/PycharmProjects/base
  3. Process finished with exit code 0

resource

  • [文档] docs.python.org/3
  • [规范] www.python.org/dev/peps/pep-0008
  • [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
  • [源码] www.python.org/downloads/source
  • [ PEP ] www.python.org/dev/peps
  • [平台] www.cnblogs.com
  • [平台] gitee.com


Python具有开源、跨平台、解释型、交互式等特性,值得学习。

Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。

代码的书写要遵守规范,这样有助于沟通和理解。

每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。

Python3基础 os.path.dirname 对路径字符串进行处理 返回所在文件夹的路径的更多相关文章

  1. Python3基础 os.path.basename 处理路径字符串,返回文件的名字

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. Python3基础 os.path.getsize 获得文件的大小

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. Python3基础 os.path.splitext 处理文件名,得到文件名+扩展名

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. 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 ...

  5. 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 ...

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

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

  7. Python3基础 sys.path.append 增加模块的搜索路径

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. python3 获取当前路径及os.path.dirname的使用

    方法一: import sys,os os.getcwd()#然后就可以看见结果了 方法二: import os os.path.dirname(os.path.realpath('__file__' ...

  9. 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__)返回 ...

随机推荐

  1. 对Django框架架构和Request/Response处理流程的分析(转)

    原文:http://blog.sina.com.cn/s/blog_8a18c33d010182ts.html 一. 处理过程的核心概念 如下图所示django的总览图,整体上把握以下django的组 ...

  2. table的td的1%

    使用media-obj和media-bd类似的样式,大多数采用的是display: table-cell(即是table中td)来实现.当然设置display是不够,还要根据情况设置width.如下面 ...

  3. socke+epoll

    读: #define V5CLI_READ_MSG_LEN 1024 char readMsg[V5CLI_READ_MSG_LEN]; ; ; )) > ){ n += nread; }//读 ...

  4. 005-spring boot 2.0.4-jdbc升级

    一.概述 Springboot2默认数据库连接池选择了HikariCP为何选择HikariCP理由一.代码量理由二.口碑理由三.速度理由四.稳定性理由五.可靠性HikariCP为什么这么快优化并精简字 ...

  5. 学JS必看-JavaScript数据结构深度剖析

    回归简单 要理解JavaScript,你得首先放下对象和类的概念,回到数据和代码的本原.前面说过,编程世界只有数据和代码两种基本元素,而这两种元素又有着纠缠不清的关系.JavaScript就是把数据和 ...

  6. layer,一个可以让你想到即可做到的javascript弹窗(层)解决方案

    学习网址:http://layer.layui.com/ 下载地址:http://res.layui.com/download/layer-v2.1.zip 我们提到的基础参数主要指调用方法时用到的配 ...

  7. (转)Elasticsearch索引mapping的写入、查看与修改

    mapping的写入与查看 首先创建一个索引: curl -XPOST "http://127.0.0.1:9200/productindex" {"acknowledg ...

  8. PAT 1066 Root of AVL Tree[AVL树][难]

    1066 Root of AVL Tree (25)(25 分) An AVL tree is a self-balancing binary search tree. In an AVL tree, ...

  9. PAT 1032 Sharing[hash][链表][一般上]

    1032 Sharing (25)(25 分) To store English words, one method is to use linked lists and store a word l ...

  10. C#+Aspose.Cells 导出Excel及设置样式 (Webform/Winform)

    在项目中用到,特此记录下来,Aspose.Cells 不依赖机器装没有装EXCEL都可以导出,很方便.具体可以参考其他 http://www.aspose.com/docs/display/cells ...