![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
python
鲨鱼辣椒请战
这个作者很懒,什么都没留下…
展开
-
Python hasattr() 、getattr()、setattr() 函数
hasattr() 函数描述:hasattr() 函数用于判断对象是否包含对应的属性。语法:hasattr(object, name)参数:object – 对象name – 字符串,属性名。返回值:如果对象有该属性,则返回True, 否则返回False.实例:class Coordinate: x = 10 y = -5 z = 0 point1 = Coordinate() print(hasattr(point1, 'x'))print(原创 2021-03-25 14:55:15 · 196 阅读 · 0 评论 -
python 报错 SyntaxError: Non-ASCII character ‘\xe6‘ in file E:\PycharmProjects\lianxi\re 111.py on lin
python 报错 SyntaxError: Non-ASCII character ‘\xe6’ in file E:\PycharmProjects\lianxi\re 111.py on line 17, but no encoding declared;解决方法:在脚本中加入# encoding: utf-8原创 2021-03-12 15:41:15 · 221 阅读 · 0 评论 -
python 调 sh 文件(本地 或 远程)
本地调用:import oscmd = './re 111.sh'data = os.popen(cmd)print(data.read())远程调用:ssh_tool("ip地址", '端口', "用户名", "密码", 'sh /etc/ansible/getversion.sh')调用命令原创 2021-03-12 15:34:47 · 1053 阅读 · 0 评论 -
echarts 力导向布局图节点显示图片
echarts 力导向布局图节点显示图片前端(html):<!DOCTYPE html><html><head> <meta charset="utf-8"> <title> 系统关系图 </title> <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.css"> <link rel="stylesheet原创 2020-12-28 17:31:28 · 1232 阅读 · 0 评论 -
python 求两个列表的交集,并集,差集
a = [1, 5, 8, 9, 6]b = [2, 1, 8, 6, 9, 3, 7]print('求两个列表的交集intersection:', list(set(a).intersection(set(b)))) # 求两个列表的交集print('求两个列表的差集difference: ', list(set(a).difference(set(b)))) # 求两个列表的差集print('求两个列表的并集union: ', list(set(a).union(set原创 2020-12-25 17:12:27 · 1087 阅读 · 0 评论 -
python Counter统计列表中的元素个数
from collections import Counter # 导包a = [[1, 2, 3], [1, 2, 3], [4, 5, 6]]b = [str(i) for i in a] # 把二维数组中的列表转换成字符串不然报错# for i in Counter(b):# print(i)print(Counter(b))结果:原创 2020-12-25 17:02:26 · 2241 阅读 · 0 评论 -
Django admin 创建超级用户
# 创建超级用户python manage.py createsuperuseradmin.py 注册from django.contrib import adminfrom .models import Classify, Food# Register your models here.@admin.register(Classify)class ClassitfyAdmin(admin.ModelAdmin): # list_display 设置要显示在列表中的字段(id字段是原创 2020-12-24 15:21:35 · 740 阅读 · 0 评论 -
Django admin 页面优化调整
from django.contrib import adminfrom .models import Book# class MyAdminSite(admin.AdminSite):# site_header = '自定义后台管理系统'# site_title = '后台管理系统'admin.site.site_header = '自定义后台管理系统'admin.site.site_title = '后台管理系统'@admin.register(Book)class原创 2020-12-24 15:13:53 · 551 阅读 · 0 评论 -
python django 修改启动项目的域名(两种方式)
一般情况下, django项目运行后ip是:127.0.0.1:8000,如何修改ip,实现项目共享一、Django 启动项目命令默认项目启动命令:python manage.py runserver指定端口启动命令:python manage.py runserver ip:port如果想让别人共享项目,可以在同一个无线网或内网下,然后设置本机IP地址启动,另一台电脑便可以直接访问IP地址加端口,进行访问了。二、修改配置(使用pycharm)修改运行ip,点击run—Edit Co原创 2020-12-24 15:08:28 · 2185 阅读 · 0 评论 -
python3 集合的基本用法
python3 集合的基本用法文章目录python3 集合的基本用法集合的基本操作1、添加元素2、移除元素3、计算集合元素个数4、清空集合5、判断元素是否在集合中存在集合内置方法完整列表add()clear()copy()difference()difference_update()discard()intersection()intersection_update()isdisjoint()issubset()issuperset()pop()remove()symmetric_differenc.原创 2020-12-22 17:37:40 · 75 阅读 · 0 评论 -
python3 字符串的基本用法
python3 字符串的基本用法文章目录Python3 字符串Python 访问字符串中的值Python 字符串更新Python 字符串运算符Python 字符串格式化Python 三引号实例(Python 3.0+)f-stringUnicode 字符串Python 的字符串内建函数capitalize()描述语法参数返回值实例center(width, fillchar)语法参数返回值实例count(str, beg=0, end=len(string))描述语法参数返回值实例bytes..原创 2020-12-22 16:31:39 · 344 阅读 · 2 评论 -
python3 数字的基本方法用法
python3 数字的基本方法用法文章目录Python3 数字(Number)Python 数字类型转换Python 数字运算数字函数abs(x)ceil(x)cmp(x, y)exp(x)fabs(x)floor(x)log(x)log10(x)max(x1, x2, .....)min(x1,x2,.....)modf(x)pow(x, y)round(x[,n])sqrt(x)随机数函数choice(seq)randrange([start,]stop[,step])random()s.原创 2020-12-22 14:17:00 · 259 阅读 · 0 评论 -
Python 3 字典的基础方法
Python 3 字典的基础方法文章目录Python 3 字典的基础方法Python3 字典访问字典里的值修改字典删除字典元素字典键的特性字典内置函数&方法Python字典包含了以下内置函数:len(dict)str(dict)type(variable)Python字典包含了以下内置方法:dict.clear()dict.copy()dict.fromkeys(seq[, val])dict.get(key, default=None)key in dictdict.items()dict..原创 2020-12-18 16:14:00 · 103 阅读 · 1 评论 -
python3 元组的基础方法
python3 元组的基础方法文章目录python3 元组的基础方法Python 3 元组访问元组修改元组删除元组元组运算符元组索引,截取元组内置函数关于元组是不可变的Python 3 元组Python的元组与列表类似,不同之处在于元组的元素不能修改。元组使用小括号(),列表使用方括号[]。元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可。>>> tup1 = ('Google', 'Runoob', 1997, 2000)>>> tu.原创 2020-12-17 16:29:13 · 166 阅读 · 0 评论 -
python3 列表的基础方法
python3 列表的基础方法文章目录python 3 列表(List)访问列表中的值更新列表删除列表元素Python 列表脚本操作符Python列表截取与拼接嵌套列表Python 列表函数&方法Python包含以下函数:len()max()min()list()Python 包含以下方法:list.append()list.count()list.extend()list.index()list.insert()list.pop()list.remove()list.reverse()l.原创 2020-12-17 15:48:37 · 109 阅读 · 0 评论 -
python2 解决编码问题
python2 解决编码问题实现zabbix 告警推送企业微信 ,结果脚本不能发送中文,一直报错:UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xb8 in position 0: invalid start byte找了好久终于找到解决办法,如下:send_data = simplejson.dumps(send_values, ensure_ascii=False).encode(“raw_unicode_escape”).decode(原创 2020-12-09 10:10:34 · 189 阅读 · 0 评论