Python中对变量是否为None的判断

Python中对变量是否为None的判断
差点因为在None的判断上吃各小亏,SO,转载一下。 三种主要的写法有: 第一种:if X is None; 第二种:if not X; 当X为None, False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()这些时,not X为真,即无法分辨出他们之间的不同。 第三种:if not X is None; 在Python中,None、空列表[]、空字典{}、空元组()、0等一系列代表空和无的对象会被转换成False。除此之外的其...

python3 dbutils 解决mysql连接关闭及返回数据格式为字段对应值问题

python3 dbutils 解决mysql连接关闭及返回数据格式为字段对应值问题
自己重新封装了一个Mysql的命令执行的类,但是经常会自动关闭mysql数据库的连接,自己写法完全按照官方的来的,但是就是会出问题,自己也是一脸懵逼,后来启用dbutils解决此问题了,但是又出新问题,就是查询返回数据是tuple,而且是0,1,2,3,4……等对应查询的值,并非字段返回字段对应值,艾玛,想着不可能有这么大缺陷,然后一顿狂看接口API,最终找到解决方法。下看如...

python pymysql 报错 pymysql.err.InterfaceError: (0, ”) 或 AttributeError: ‘dict’ object has no attribute ‘Exception’

python pymysql 报错 pymysql.err.InterfaceError: (0, ”) 或 AttributeError: ‘dict’ object has no attribute ‘Exception’
因为个人一直秉承着最好用最新版的原则,所以一直在使用Python3,结果今天在使用pymysql这个库,然后自己封装了一个mysql的类,但是各种报错。错误如下图: AttributeError: 'dict' object has no attribute 'Exception' 当时自己百度了很多资料,基本都没解决问题。先给大家看我封装的类的代码吧。如下:   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2...

python 转(生成) 打包exe 方法pyinstaller详解

python 转(生成) 打包exe 方法pyinstaller详解
首先你需要安装pyinstaller,这里推荐你用python自带的方法安装。命令是:   pip install pyinstaller Tips: 出现异常请更新pip:python -m pip install --upgrade pip pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz 如果你是windows下,执行此命令后,就不用再安装其他的了。 ------如果你执行了上述命令,则下面的内容可忽略---...

python3.7+ 处理xml 字符串 转 dict 字典格式

python3.7+ 处理xml 字符串 转 dict 字典格式
直接使用https://github.com/martinblech/xmltodict 这个库就可以了。 我自己还吭吃瘪肚的写呢。。。。MD太智障了。 人家早都写好了,顺手点个赞。!!! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 7...

python 处理xml (或xml文件)

python 处理xml  (或xml文件)
在这里我要先吐槽一下,真的,网上太多太多的傻缺, 真的服了,说python3.4+ 用xml.etree.ElementTree  说用这个方法处理的人十有八九都TM是脑残吧?!!! python 3.3+ 弃用xml.etree.ElementTree 不信的自己去搜搜,好多好多文章 python 3.3+ 说用这个方法。。。真的是。。。。。。。。 ------------正文-------------- 下面说说 python 2 3+ 应该用什么处理xml xml.sax P...

Python + Zeep创建一个SOAP API客户端

Python + Zeep创建一个SOAP API客户端
我尝试用Python + Zeep 创建一个SOAP API客户端,所以我会留下笔记。 环境 macOS High Sierra 10.13.6 Python 3.6.6 肥皂3.1.0 它对应于SOAP 1.1 / 1.2   此外,WSDL有一个SOAP API,假设你使用。 维基百科对WSDL版本等有帮助。 Web服务描述语言 - 维基百科 什么是Zeep? 根据官方文件 快速而现代的Python SOAP客户端亮点: 兼容Python 2.7,3.3,3.4,3.5,3.6和PyPy 构建在lx...

python soap协议库 zeep 各种问题解决方法

python soap协议库 zeep 各种问题解决方法
注意,以下报错都是在python3环境下报错的。 问题一:报错“zeep.exceptions.Fault: Unknown fault occured” 1 2 3 4 5 6 7 8 9 10 11 12 Traceback (most recent call last): File "E:/test/ddddddddddddd.py", line 51, in new_vlan = clientVlan.service.createIpObject(args) #createIpObject File "E:\Python37\lib\site-packages\zeep\...

SOAP python demo 两例

SOAP python demo 两例
SOAP 协议使用的Python,其中有一个库是zeep,这个库一直有人维护,而且是最新的。 第一个demo: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 # -*-coding:utf-8-*- from requests.auth import HTTPBasicAuth # or HTTPDigestAuth, or OAuth1, etc. from...

python @classmethod 使用详解 看完即懂

python @classmethod 使用详解 看完即懂
官方的说法: classmethod(function) 中文说明: classmethod是用来指定一个类的方法为类方法,没有此参数指定的类的方法为实例方法,使用方法如下: class C: @classmethod def f(cls, arg1, arg2, ...): ... 看后之后真是一头雾水。说的啥子东西呢??? 自己到国外的论坛看其他的例子和解释,顿时就很明朗。 下面自己用例子来说明。 看下面的定义...