随笔分类 -  python小知识

一些python的小用法
摘要:解决No module named 'mpl_toolkits.basemap'问题 1. 手动下载 whl文件 下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#basemap 2. 搜索 basemap, pyproj, 版本需与python版本一 阅读全文
posted @ 2022-05-31 12:04 是阿杰呀 阅读(757) 评论(0) 推荐(0) 编辑
摘要:1. clear() 删除字典内所有元素 dict = {'name': 'jesse', 'age': 18, 'sex': 'male'} dict.clear() # dict = {} 2. pop() 删除字典给定键key所对应的值, 返回被删除的值 dict = {'name': 'je 阅读全文
posted @ 2022-04-14 15:38 是阿杰呀 阅读(7884) 评论(0) 推荐(0) 编辑
摘要:1. 字符串补位 左右中 对齐 str1 = 'space' str1.ljust(10, '-') # 左对齐 'space ' str1.rjust(10, '-') # 右对齐 ' space' str1.center(10, '-') # 居中对齐 '--space ' 2. 字符串补零 s 阅读全文
posted @ 2022-04-12 15:45 是阿杰呀 阅读(678) 评论(0) 推荐(0) 编辑
摘要:1. media 路径配置 项目目录文件夹下的 settings.py MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 项目目录文件夹下的 urls.py from django.conf.urls import 阅读全文
posted @ 2022-03-10 11:14 是阿杰呀 阅读(57) 评论(0) 推荐(0) 编辑
摘要:1. 下载虚拟环境包 pip install virtualenv 2. 创建虚拟环境 在当前目录下创建 virtualenv -p python venv1 3. 进入虚拟环境 cd venv1/Scripts 输入activate 4. 退出虚拟环境 # 在 Script目录下 deactiva 阅读全文
posted @ 2022-03-03 18:54 是阿杰呀 阅读(53) 评论(0) 推荐(0) 编辑
摘要:enumerate 枚举列表, 取出每个元素的下标和元素的值, 返回元组 点击查看代码 list1 = [1, 2, 3, 4] for i in enumerate(list1): print(i) print('下标:',i[0], '元素:', i[1]) 阅读全文
posted @ 2022-01-20 10:17 是阿杰呀 阅读(201) 评论(0) 推荐(0) 编辑
摘要:获取问价你的创建时间 import os os.path.getctime(file_path) 获取文件的修改时间 os.path.getmtime(file_path) 注: 获取的是 时间戳 阅读全文
posted @ 2022-01-19 10:23 是阿杰呀 阅读(1399) 评论(0) 推荐(0) 编辑
摘要:获取当前时间戳 import time time.time() 时间戳 转 时间 2.1 time.localtime(time.time()) 2.2 import datetime datetime.datetime.fromtimestamp(time.time()) 时间 转 时间戳 d1 阅读全文
posted @ 2022-01-19 10:06 是阿杰呀 阅读(211) 评论(0) 推荐(0) 编辑
摘要:【python】nonlocal关键字 ''' nonlocal关键字用来在函数或其他作用域中使用外层(非全局)变量。 ''' def work(): x = 0 def new_work(): nonlocal x x += 3 return x return new_work f=work() 阅读全文
posted @ 2021-06-04 19:45 是阿杰呀 阅读(622) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示