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)的更多相关文章
- 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(__file__)的使用
在编程时,我们要获取当前文件所在的路径,以适合所有的工程,建立相对路径. python的os.path.dirname(__file__)非常好用,建议大家使用: import os FILE = o ...
- python中os.path.dirname(__file__) 命令行 参数没有绝对路径导致数据库找不到
(1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: python d:/python ...
- 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与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 #该文件所在位置 ...
- 第十八篇 模块与包--time&random模块&模块导入import(os.path.dirname(os.path.abspath(__file__)))
模块 在Python中, 一个.py文件就称为一个模块. 使用模块的好处: 1. 最大的好处就是大大提高了代码的可维护性 2. 编写代码不必从零开始.一个模块编写完毕,就可以被其他地方引用.在写其他程 ...
随机推荐
- 选项卡控件(TabControl)的操作
移除选项卡和删除不同:前者可以从控件中移除不需要的选项,后者可以删掉整个控件.
- Robotium之“去哪儿旅行”
Robotium基于APK自动化测试,只有APK文件,没有源代码. Eclipse 默认的debug keystore可以在Windows->Preferences->Android-&g ...
- 【Python】Python基础教程系列目录
Python是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. 在现在的工作及开发当中,Python的使用越来越广泛,为了方便大家的学习,Linux大学 特推出了 <Python基 ...
- BZOJ5091 摘苹果(概率期望)
大胆猜想每一步都相当于是第一步.稍微验证一下发现是对的.就做完了. #include<iostream> #include<cstdio> #include<cmath& ...
- BZOJ4921 互质序列
即求删掉一个子序列的gcd之和.注意到前后缀gcd的变化次数都是log级的,于是暴力枚举前缀gcd和后缀gcd即可. #include<iostream> #include<cstd ...
- jQuery高度及位置操作
1. 获取滑轮位置,scrolltop:上下滚动的意思. <!DOCTYPE html> <html lang="en"> <head> < ...
- msf下的LNK漏洞(CVE-2017-8464)利用
0x01 前言 RCE漏洞存在于Windows处理LNK文件的环节.攻击者利用漏洞可以获得与本地用户相同的用户权限.被使用此漏洞攻击时,用户权限较少的账户相较管理员权限的用户受到的影响更小. 攻击者可 ...
- ACE服务端编程2:ACE跨平台之数据类型和宽字符
ACE网络库的主要优势之一就是跨平台,ACE提供了操作系统API和编译器级别的跨平台解决方法,使开发人员不用再去关心操作系统和编译器的差异,但因此也带来了ACE的复杂性. ACE网络库的组织结构主要分 ...
- (转)JAVA 十六个常用工具类
一. org.apache.commons.io.IOUtils closeQuietly 关闭一个IO流.socket.或者selector且不抛出异常.通常放在finally块 toString ...
- CentOS7.2下安装mongoDB3.2.8
最近在又在倒腾MongoDB,把安装配置的相关命令贴出来 1.下载 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70- ...