在改章节中,我们主要介绍文件位置的内容,自我感到有个不错的建议和大家分享下
一、意识下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体具寄存的位置。
如果说生命是一座庄严的城堡,如果说生命是一株苍茂的大树,如果说生命是一只飞翔的海鸟。那么,信念就是那穹顶的梁柱,就是那深扎的树根,就是那扇动的翅膀。没有信念,生命的动力便荡然无存;没有信念,生命的美丽便杳然西去。(划线处可以换其他词语)
如果我们在eclipse中辑编如下代码,则输入该文件地点的完整路径:
但是如果我们在python自带的IDLE或Python command line中辑编,则会现出如下误错:
我感到很惊讶,本原以为是自己写错了,但是复反写了几遍都犯错,最好google了一下,找到如下谜底:
下面说的清清楚楚。这里不再累述。
荐推浏览:关于python文件作操:http://www.cnblogs.com/rollenholt/archive/2012/04/23/2466179.html
文章结束给大家分享下程序员的一些笑话语录: 祝大家在以后的日子里. 男生象Oracle般健壮; 女生象win7般漂亮; 桃花运象IE中毒般频繁; 钱包如Gmail容量般壮大, 升职速度赶上微软打补丁 , 追女朋友像木马一样猖獗, 生活像重装电脑后一样幸福, 写程序敲代码和聊天一样有**。
相关推荐
主要介绍了python3中的os.path.dirname(__file__)的使用,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
这篇文章主要介绍了如何使用python3获取当前路径及os.path.dirname的使用,文中通过示例代码...python中的os.path.dirname(__file__)的使用 (1)当”print os.path.dirname(__file__)”所在脚本是以完整路径被运行的, 那
path = os.path.dirname(os.path.abspath(__file__)) for p in os.listdir(path): p_inner = os.path.join(path, p) if os.path.isdir(p_inner): src_path.append(p_inner) # 递归获取src_path里每个目录里的要...
本文实例讲述了python中os操作文件及文件路径的方法。分享给大家供大家参考。具体分析如下: ...复制代码 代码如下:print os.path.dirname(os.path.abspath(“__file__”)) print os.path.pardir pr
os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 这个是获取当前文件的上一级目录 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 这个是把路径添加到系统的环境...
filename=os.path.abspath(__file__) dirname=os.path.dirname(filename) info_path=dirname+os.sep+'user.info' def write_balance(data): f=open(info_path,'wb') pickle.dump(data,f) f.close() 作者:...
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templa
1.vue项目中config文件下index.js中打包配置 build: { // Template for index.html index: path.resolve(__dirname, '../yiTownWebApp/index.html'), // Paths assetsRoot: path.resolve(__dirname, '../...
dir_in = os.path.join(os.path.dirname(__file__), r"oldApp") dir_in = unicode(dir_in, r"GBK") dir_out = os.path.join(os.path.dirname(__file__), r"newApp") dir_out = unicode(dir_out, r"GBK") ...
audio_path = os.path.join(os.path.dirname(__file__), "audio") def randv(): # 生成随机初速度 v = random.random() * 22 while (v ): v = random.random() * 22 return v def rand_color(): # 随机生成...
log_dir1=os.path.join(os.path.dirname(os.path.dirname(__file__)),logs) today = time.strftime('%Y%m%d', time.localtime(time.time())) full_path=os.path.join(log_dir1,today) if not os.path.exists(full_...
os.path.dirname(os.path.abspath(__file__)), 'components/helloworld.js') component = HelloWorldComponent() component.render(props=['Hello', 'World']) 标签:ReactiPy
前言:在自动化测试中,经常需要查找操作文件,比如说查找配置文件(从而读取...os.path.dirname(__file__) 获取当前文件的所在路径 输入: import os from reptile import * print(os.path.dirname(__file__)) 输出:
# -*- coding: utf-8 -*- ...BASE_DIR = os.path.dirname(os.path.abspath(__file__)) class FileOperation: def __init__(self): self.dic = dict() self.toml_file_path = os.path.join(BASE_DIR,
pwd = os.path.dirname(os.path.realpath(__file__)) sys.path.append(pwd+"../") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings") import django django.setup() from apps.city....
file_path = os.path.abspath(os.path.dirname(__file__)) # 获取当前文件目录 print(file_path) root_path = os.path.dirname(file_path) # 获取文件上级目录 data_path = root_path + '\\data' # 拼接data文件夹...
FILE_DIR = os.path.dirname(os.path.abspath(__file__)) #======================================================== # 文件操作 #======================================================== def get_filelist1...
下面这一串代码是 PyQt5 库下 __ init__.py 文件中的内容: def find_qt(): import os, sys qtcore_dll = '\\Qt5Core.dll' dll_dir = os.path.dirname(sys.... dll_dir = os.path.dirname(__file__) + '\\Qt\\bin'