代码改变世界

随笔分类 -  Python学习笔记

anaconda prompt execute jupyter notebook, can't open notebook

2021-01-24 19:59 by 钱先生, 41 阅读, 收藏, 编辑
摘要: learned from: https://stackoverflow.com/questions/53982363/anaconda-jupyter-doesnt-open-in-browser issue: doesn't open notebook in browser solution: m 阅读全文

conda 创建新环境下载包失败

2021-01-24 16:38 by 钱先生, 328 阅读, 收藏, 编辑
摘要: 转自; https://blog.csdn.net/u011939755/article/details/80863227?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1.control&depth_1- 阅读全文

failed to install jupyter_contrib_nbextensions

2021-01-23 23:17 by 钱先生, 259 阅读, 收藏, 编辑
摘要: Command executed: conda install -c conda-forge jupyter_contrib_nbextensions Issue ERROR conda.core.link:_execute(698): An error occurred while install 阅读全文

failed to install nb_conda

2021-01-23 22:59 by 钱先生, 1806 阅读, 收藏, 编辑
摘要: Command executed: conda install nb_conda Issue ERROR conda.core.link:_execute(698): An error occurred while installing package 'https://mirrors.tuna.t 阅读全文

Python Socket 通信

2018-06-27 08:05 by 钱先生, 248 阅读, 收藏, 编辑
摘要: 参考: http://www.cnblogs.com/alex3714/articles/5830365.html Socket A network socket is an endpoint of a connection across a computer network. Today, mos 阅读全文

Python异常处理

2018-06-26 09:27 by 钱先生, 224 阅读, 收藏, 编辑
摘要: 参考: http://www.cnblogs.com/wupeiqi/articles/5017742.html 常见异常类型 AttributeError 试图访问一个对象没有的属性. IOError 输入/输出异常, 通常是无法打开文件(python2.7是这样. python3无法打开文件是F 阅读全文

Python 反射

2018-06-26 08:48 by 钱先生, 216 阅读, 收藏, 编辑
摘要: 反射 通过字符串映射或修改程序运行时的状态,属性,方法. 有以下四种方法: getattr(object, name, default = None) hasattr(object, name) setattr(x,y,v) delattr(x,y) #!/usr/bin/python # -*- 阅读全文

DDT模块

2018-06-22 11:48 by 钱先生, 621 阅读, 收藏, 编辑
摘要: 转自: https://www.cnblogs.com/frost-hit/p/8277637.html Python DDT(data driven tests)模块心得 关于ddt模块的一些心得,主要是看官网的例子,加上一点自己的理解,官网地址:http://ddt.readthedocs.io 阅读全文

Python面向对象进阶

2018-06-21 08:19 by 钱先生, 220 阅读, 收藏, 编辑
摘要: 静态方法 静态方法只是名义上归类管理, 实际上在静态方法里访问不了类或实例中的任何属性. 静态方法作用: 把一个方法变成静态方法, 相当于切断了它和类的关联, 不会自动传self. 就是一个函数. a. 创建方法时不传入参数self. b. 若一定要传入参数, 调用该方法时需要把实例化对象传给自己, 阅读全文

Python 多态

2018-06-19 08:09 by 钱先生, 234 阅读, 收藏, 编辑
摘要: 多态(polymorphism) 含义: 允许将你对象设置成为和一个或更多其它子对象相等的技术, 赋值之后, 父对象就可以根据当前赋值给它的子对象的特性以不同的方式运作. 即: 允许将子类类型的指针赋值给父类类型的指针. 作用: 接口重用 即为了类在继承和派生的时候,保证使用"家谱中任一类的实例的某 阅读全文

Python 继承

2018-06-12 10:06 by 钱先生, 329 阅读, 收藏, 编辑
摘要: 继承 实现继承, 可以通过"继承"(Inheritance) 和 "组合"(Composition) 来实现. 在某些语言中, 一个子类可以继承多个基类, 但是一般情况下, 一个子类只能有一个基类, 要实现多重继承,可以通过多级继承来实现. 继承概念的实现方式主要有两类: 实现继承 实现继承是指使用 阅读全文

Python 面向对象(二)

2018-06-11 08:43 by 钱先生, 201 阅读, 收藏, 编辑
摘要: 类 ==> 实例化 ==> 实例对象 __init__ 构造函数 self.name = name # 属性, 成员变量 def sayhi() # 方法, 动态属性 def get_heart(self): return self.__heart # 提供对外访问接口, 但是外部只能获取其值,不能 阅读全文

Python 类

2018-06-08 09:02 by 钱先生, 214 阅读, 收藏, 编辑
摘要: #!/usr/bin/python # -*- coding: utf-8 -*- # 创建类并实例化 """ 方法1: 新建类, 并实例化, 可直接调用类中的方法返回结果. 弊端: 没有参数, 创建多个对象时分不清哪个是哪个. """ class Dog(object): def sayhi(se 阅读全文

Python 面向对象(一)

2018-06-07 08:18 by 钱先生, 182 阅读, 收藏, 编辑
摘要: 面向过程编程 (Procedural Programming) Prodcedural programming uses a list of instructions to tell the computer what to do setp-by-step. 面向过程编程依赖 --> procedu 阅读全文

Python subprocess 模块

2018-06-01 11:09 by 钱先生, 393 阅读, 收藏, 编辑
摘要: 注: 本文中代码均在shell中执行. os.system 输出命令结果到屏幕, 返回命令执行状态. 若想将os.system的命令结果保存为一个变量, 要用到popen. os.popen("dir").read() # 会保存命令的执行结果输出 要同时得到命令结果和命令执行状态, 需要用到sub 阅读全文

Python 执行主程序

2018-06-01 08:47 by 钱先生, 4058 阅读, 收藏, 编辑
摘要: 主程序里的代码包含的东西比较多, 如果在程序的.py文件里执行还要再调一遍方法, 但通常这个调用在测试完结后是要删掉的. 那么问题来了, 如果把这个代码直接发给别人, 执行时要再加上调用, 这个就很烦了. 要解决这个问题, 可以单独写一个执行文件: 这样需要执行或者测试时, 直接在这个文件里执行就可 阅读全文

Python正则

2018-05-19 20:39 by 钱先生, 233 阅读, 收藏, 编辑
摘要: 常用正则表达式符号 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 '.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行 '^' 匹配字符开头,若指定flags MULTILINE,这种也可以匹 阅读全文

Python logger /logging

2018-05-19 18:50 by 钱先生, 328 阅读, 收藏, 编辑
摘要: # !/user/bin/python # -*- coding: utf-8 -*- ''' subprocess : 需要在linux平台上测试 shell logging ''' import logging # 将日志输出在文件里 # logging.basicConfig(filename="app.log", level=logging.DEBUG) logging.basicCo... 阅读全文

Python hashlib

2018-05-19 18:01 by 钱先生, 169 阅读, 收藏, 编辑
摘要: # !/user/bin/python # -*- coding: utf-8 -*- import hashlib # 可提供MD5算法 , 防止内页被篡改 (若内页未被篡改, MD5的值是不变的) m = hashlib.md5() m.update(b"hello") print(m.hexdigest()) # 生成md5值. m.update(b"it's me") # 不是用... 阅读全文

Python ymal 模块和configparser

2018-05-19 18:00 by 钱先生, 492 阅读, 收藏, 编辑
摘要: ymal : 是一种config文件 阅读全文