Python
cym0359
这个作者很懒,什么都没留下…
展开
-
python判断文件和文件夹是否存在、创建文件夹
python判断文件和文件夹是否存在、创建文件夹>>> import os>>> os.path.exists('d:/assist')True>>> os.path.exists('d:/assist/getTeacherList.py')True>>> os.path.isfile('d:/assi...转载 2019-01-11 09:51:20 · 1302 阅读 · 0 评论 -
对于\xa0的处理
在用Python3处理英文文档时遇到split(' ')无法分开的空格,使用encode('utf8')编码后发现它并不是空格,而是\xa0,它其实是latin1编码字符,为了使\xa0像空格那样分开字符,可以直接调用split()即可...转载 2019-04-24 14:47:29 · 468 阅读 · 0 评论 -
Python 调用 C 动态链接库,包括结构体参数、回调函数
环境准备ctypes 包准备使用 ctypes,需要首先安装 python-dev 包:Ubuntu:$ sudo apt-get install python-dev -yCentOS:$ sudo yum install python-devel -y这里主要包含了ctypes包。.so 文件准备将你的 C 代码编译成 .so 文件。这里假设目标文件是...转载 2019-04-09 15:55:08 · 4853 阅读 · 3 评论 -
配置pycharm使用pyQt5
官网下载安装pycharm:https://www.jetbrains.com/pycharm/1、点击:File -》Settings图 32、Tools -》 External Tools -》点击“+”号(图4)(ps:下面是我配置好的,你的软件还没有很正常,继续往下看)图 43、设置Qt Designer修改三个地...原创 2019-04-08 13:56:43 · 228 阅读 · 0 评论 -
Python Matplotlib--legend
legend 显示图例1 legend基础函数原型 legend(*args, **kwargs) 当len(args) == 2 args 是[artist]和[label]的集合当len(args) == 0 args会自动调用get_legend_handles_labels()生成 等价于 handles, l...转载 2019-02-26 16:30:09 · 574 阅读 · 0 评论 -
Python matplotlib format
The following format string characters are accepted to control the line style or marker: ================ =============================== character ...原创 2019-02-21 10:50:55 · 611 阅读 · 0 评论 -
Python Matplotlib 画多个图保存到一个pdf文件中
官方文档例子pylab_examples example code: multipage_pdf.py"""This is a demo of creating a pdf file with several pages,as well as adding metadata and annotations to pdf files."""import datetimeimpo...原创 2019-02-26 10:46:27 · 11162 阅读 · 0 评论 -
python3中encode和decode跟python2的区别
python3中encode和decode跟python2还是有一定的区别的,在python3中: encode(编码):按照某种规则将“文本”转换为“字节流”。 python 3中表示:unicode变成str decode(解码):将“字节流”按照某种规则转换成“文本”。 python3中表示:str变成unicode字符串在Python内部的表示是Unicode编码...原创 2019-03-01 13:44:07 · 988 阅读 · 0 评论 -
Python 函数装饰器
装饰器(Decorators)是 Python 的一个重要部分。简单地说:他们是修改其他函数的功能的函数。他们有助于让我们的代码更简短,也更Pythonic(Python范儿)。大多数初学者不知道在哪儿使用它们,所以我将要分享下,哪些区域里装饰器可以让你的代码更简洁。 首先,让我们讨论下如何写你自己的装饰器。这可能是最难掌握的概念之一。我们会每次只讨论一个步骤,这样你能完全理解它。一切皆对...转载 2019-02-14 09:13:14 · 95 阅读 · 0 评论 -
Python 匿名函数
不定义函数名的函数。lambda 表达式:lambda parameter_list: expression1例:def add(x, y): return x + yadd(1, 2)# 等同于:f = lambda x,y: x+yf(1, 2)12345678三元表达式:条件为真时返回的结果 if 条件判断 else 条件为假时的返回...原创 2019-02-13 15:43:33 · 98 阅读 · 0 评论 -
Python利用matplotlib,读取excel数据生产scatter图
# -*- coding: utf-8 -*-# @Time : 2018/9/20 9:38# @Author : Lin Sen# @Site : # @File : scatter.py# @Software: PyCharm Community Editionimport numpy as npimport matplotlib.pyplot as p...原创 2019-01-23 09:46:30 · 2164 阅读 · 0 评论 -
Python调用函数,带扩和和不带括号的区别
调用函数,如果带括号,那么是调用函数运行后的结果,调用函数不带括号,调用的是函数本身例如def cun (a,b):return a+bprint(cun) : 调用函数,打印的是函数print(cun(2,3)),调用函数运行后结果,打印的是 5...转载 2019-01-10 09:53:04 · 896 阅读 · 0 评论 -
Python TypeError: 'NoneType' object is not callable
I am mere a beginner of Python. I am getting the following error and suspect that it has something to do with the dictionary I've used as switch case (since python does not provide switch ). Follow...原创 2019-01-10 09:43:57 · 2837 阅读 · 0 评论 -
Python之Matplotlib库常用函数大全(含注释)
plt.savefig(‘test’, dpi = 600) :将绘制的图画保存成png格式,命名为 testplt.ylabel(‘Grade’) : y轴的名称plt.axis([-1, 10, 0, 6]) : x轴起始于-1,终止于10 ,y轴起始于0,终止于6plt.subplot(3,2,4) : 分成3行2列,共6个绘图区域,在第4个区域绘图。排序为行优先。也...转载 2019-01-25 15:52:23 · 1073 阅读 · 0 评论 -
Python--pandas
pandas.read_excelpandas.read_excel(io, sheet_name=0, header=0, names=None, index_col=None, usecols=None, squeeze=False, dtype=None, engine=None, converters=None, true_values=None, false_values=None,...原创 2019-01-24 15:13:30 · 250 阅读 · 0 评论 -
Python time & datetime & string 相互转换
#!/usr/bin/env python# -*- coding:utf-8 -*-# @Datetime : 2017/11/23 下午12:37# @Author : Alfred Xue# @E-Mail : [email protected]# @GitHub : https://github.com/Alfred-Xue# @Blog ...转载 2019-01-08 10:54:43 · 1734 阅读 · 0 评论 -
Python--copy、deepcopy
在python中,当运行上面的代码时,如果a是字典或者列表的话,程序执行的操作并不是新建一个b变量,然后a的值复制给b,而是新建一个b变量,把b的值指向a,也就是相当于在c语言里面的新建一个指向a的指针。所以当a的值发生改变时,b的值会相应改变。但是,当我们想新建一个与a的值相等的b变量,同时b的值与a的值没有关联时,要怎么做?这时就用到copy与deepcopy了 1 impor...原创 2019-06-14 13:34:28 · 109 阅读 · 0 评论