Python——os.path.dirname(__file__) 与 os.path.join(str,str)
认识下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具体存放的位置。
Python——os.path.dirname(__file__) 与 os.path.join(str,str)的更多相关文章
- os.path.dirname(__file__)和os.path.abspath(__file__)区别
- python中os.path.dirname(__file__) 命令行 参数没有绝对路径导致数据库找不到
(1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: python d:/python ...
- python中的os.path.dirname(__file__)的使用
在编程时,我们要获取当前文件所在的路径,以适合所有的工程,建立相对路径. python的os.path.dirname(__file__)非常好用,建议大家使用: import os FILE = o ...
- 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__)返回 ...
- 转: Python中的os.path.dirname(__file__)
(1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: ...
- 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 ...
- python中的os.path.dirname与os.path.dirname(__file__)的用法
python中的os.path.dirname的用法 os.path.dirname(path) 语法:os.path.dirname(path) 功能:去掉文件名,返回目录 如: print(os. ...
- os.path.dirname(__file__)使用、Python os.path.abspath(__file__)使用
python中的os.path.dirname(__file__)的使用 - CSDN博客https://blog.csdn.net/u011760056/article/details/469698 ...
- os.path.dirname(__file__)使用
os.path.dirname(__file__)使用 该测试脚本所在的位置:D:\第1层\第2层\第3层\第4层\第5层\test11.py test11.py import os #该文件所在位置 ...
随机推荐
- query的list()和iterate()区别 面试题
query的list()和iterate()区别 1.返回的类型不一样,list返回List,iterate返回iterator 2.查询策略不同. 获取数据的方式不一样,list会直接查询数据库,i ...
- centos 7 安装配置mod_security
1.旧版本安装过程: http://blog.secaserver.com/2011/10/install-mod_security-apache2-easiest/ http://www.cnblo ...
- 动态符号链接的细节 与 linux程序的加载过程
转: http://hi.baidu.com/clivestudio/item/4341015363058d3d32e0a952 值得玩味的一篇分析程序链接.装载.动态链接细节的好文档 导读: by ...
- 动态内存管理详解:malloc/free/new/delete/brk/mmap
c++ 内存获取和释放 new/delete,new[]/delete[] c 内存获取和释放 malloc/free, calloc/realloc 上述8个函数/操作符是c/c++语言里常用来做动 ...
- C程序编译过程浅析【转】
转自:http://blog.csdn.net/koudaidai/article/details/8092647 前几天看了<程序员的自我修养——链接.装载与库>中的第二章“编译和链接” ...
- java 调用可执行文件时,ProcessBuilder异常CreateProcess error=2
java 调用其他应用程序时,可能在windows下没有问题,但是转到linux下,却会报这样那样的错误,比如有设计文件操作会报FileNotFoundException等等(如下代码): Proce ...
- Laravel 5.5 Blade::if 简介
Laravel 5.5 引入了一个新的黑科技,就是你可以使用 Blade::if 来进行一些简单的逻辑判断啦!想不出应用场景在哪?想象下面的场景: 判断一个用户是否是 admin 判断应用的开发环境不 ...
- PHP将两个二维数组合并为一个二维数组的方法
$a = array(0 => Array(id => 66,class_name => math),1 => Array(id => 67,class_name =&g ...
- UbuntuMate开机自动启动ssh服务
在文件/etc/init/ssh.conf中,有一句 start on filesystem or runlevel [2345] 如果想关闭自动启动的话,把这一局修改为start on runlev ...
- RQNOJ PID217 / [NOIP1999]拦截导弹【n^2 / LIS】
题目描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某天,雷达捕捉到敌国的导弹 ...