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

    认识下os.path.dirname(__file__)

    获取路径名:os.path.dirname()

    获取文件所在目录的完整路径:os.path.dirname(__file__)

    在django项目中的settings.py中还可以进行如下的配置:

    如配置数据库:

    1 import os
    2 DATABASE_ENGINE='sqlite3'
    3 DATABASE_NAME=os.path.join(os.path.dirname(__file__),'myAPP/mydata.db')

    其中 os.path.dirname(__file__)函数用于取出settings.py所在文件夹的位置,在用os.path.join()函数将该位置和后面指定的'myAPP/mydata.db'  字符串连接一起,实现sqlite3数据库文件mydata.db具体存放的位置。

  • 相关阅读:
    401. Binary Watch
    46. Permutations
    61. Rotate List
    142. Linked List Cycle II
    86. Partition List
    234. Palindrome Linked List
    19. Remove Nth Node From End of List
    141. Linked List Cycle
    524. Longest Word in Dictionary through Deleting
    android ListView详解
  • 原文地址:https://www.cnblogs.com/Simon-xm/p/3898208.html
Copyright © 2020-2023  润新知