Python
「已注销」
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Python3.8 模块命名导致循环引用
问题描述:今天写代码的时候遇到这样一个问题:Fatal Python error: init_import_size: Failed to import the site modulePython runtime state: initializedTraceback (most recent call last): File "C:\Users\lilingsong\AppData\Local\Programs\Python\Python38-32\lib\site.py", line原创 2020-07-22 09:55:35 · 4897 阅读 · 2 评论 -
Python Exceptions Handling
https://doughellmann.com/blog/2009/06/19/python-exception-handling-techniques/#index-1转载 2018-12-09 11:03:56 · 473 阅读 · 0 评论 -
Python Defensive Programming
文章讲了如何使用 assert, logging, 以及 unit test 实践防御性编程的技巧。defensive-programming-in-pythonhttps://swcarpentry.github.io/python-novice-inflammation/08-defensive/index.html ...转载 2018-12-09 10:43:38 · 271 阅读 · 0 评论 -
Pythoh 迭代器,可迭代对象,容器,生成器
容器一般都是可迭代对象,是一种数据结构(data structure)。很多容器(list,dict,tuple)都是可迭代对象。但是可迭代对象不一定是一种数据结构,比如打开的文件或者sockets。可迭代对象可以(can)返回迭代器。每一个可迭代对象在代码都实现了__iter__()和__next__()方法。每一个实现了__next__()方法的对象都是迭代器。生成器是一种特殊的迭代器,反之不...转载 2018-07-08 13:45:24 · 357 阅读 · 0 评论 -
Python socket 实现简单的server-client聊天
Serverimport sockethost = '127.0.0.1'port = 9999s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)# s.setsockopt()s.bind((host,port))s.listen(1)while True: conn, addr = s.accept()原创 2018-01-08 20:22:36 · 1393 阅读 · 0 评论 -
CentOs6.8 final安装源码编译安装pip报错ssl
ERROR:pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.解决方案:yum install opensslyum install openssl-dev重新编译安装python3.5,然后进入pip目录 ./setu转载 2018-01-06 16:17:34 · 382 阅读 · 0 评论 -
Python 正则表达式
1.findallstr = ":192.168.0.1:8080"host, port = re.findall(r":(\w*)", address)这里findall将仅仅输出分组中的内容。也就是虽然进行冒号的匹配但是不返回冒号。原创 2017-11-27 21:11:52 · 231 阅读 · 0 评论 -
500lines:Python实现的一个持续集成系统
GitHub500lines小项目框架详细介绍调试过程中的问题:一.作者采用从本地的一个git库写代码提交,来产生新的commit ID,用于触发新的build,事实上,每五秒轮询一次查看代码库是否有更新,在使用git add之后,还没commit之前,update_repo.sh这个文件就会将刚add的记录 reset掉。所以最好是在github clone一个代翻译 2017-11-27 21:23:25 · 1485 阅读 · 0 评论 -
Python 打包,entry_points的使用
案例:如何将source code制作成一个egg包,并且生成可以直接运行的命令目录结构:(build02) louis@jenkins:~/.virtualenv/pactest$ tree ci_test/ci_test/├── hello.py├── __init__.py└── utils ├── bye.py └── __init__.py原创 2017-12-01 21:36:54 · 10360 阅读 · 0 评论 -
Python-类与对象-子类扩展父类属性
class Human(object): def __init__(self, sex, high): self.sex = sex self.high = highclass Man(human): var = 133 def __init__(self, sex, high, job): super().__init_原创 2017-07-06 22:09:27 · 4128 阅读 · 0 评论 -
Python-元类
参考自本教程中的元类一篇 ,注释是自己的理解。http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000class Field(object): def __init__(self, name, column_type): self.name = name原创 2017-06-27 23:22:32 · 529 阅读 · 0 评论 -
PEP8 indentation写法
1.对于长字符串,每行不能超过80个字符,使用圆括号括住,新起一行使用tab缩进a = ('dddddddddddddddddd''vvvvvvvvvvvvvvvvvvvvv''nnnnnnnnnnnnnnnnnnn)原创 2017-06-14 10:42:54 · 558 阅读 · 0 评论 -
Python Excel 读写操作
需求:读取内容为Json格式的文件并写入到Excel文件主要用得到的package,import simplejsonimport xlwt#在读取某些文件时候有一些编码错误在开头声明:reload(sys)sys.setdefaultencoding('utf-8')#创建一个Workbookwb = xlwt.Workbook()#增加一个sheet原创 2017-06-22 15:46:22 · 398 阅读 · 0 评论 -
Python-yield模拟生产消费者模型
import timedef consumer(name): print("%s 准备吃包子啦!" %name) while True: baozi = yield print("包子[%s]来了,被[%s]吃了!" %(baozi,name))def producer(): c = consumer('A') c2 = con原创 2017-06-29 22:47:17 · 760 阅读 · 0 评论 -
Python正则表达式之\b
\b 称为单词边界(word boundary)符.例如只想匹配 My cat is bad.中的cat 可以使用 \bcat\bimport reharsh_str = ['hello','Cat',' cat', 'cat h','CAT', 'CAt-h','Cat_h']#re.I要在compile的时候指定,注意\b在pytho原创 2017-05-23 23:40:08 · 13826 阅读 · 0 评论 -
python egg包制作安装
python egg包制作安装见http://www.cnblogs.com/itech/archive/2011/02/13/1953268.html转载 2017-03-26 17:10:38 · 416 阅读 · 0 评论 -
python Virtualenv使用
在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4。所有第三方的包都会被pip安装到Python3的site-packages目录下。如果我们要同时开发多个应用程序,那这些应用程序都会共用一个Python,就是安装在系统的Python 3。如果应用A需要jinja 2.7,而应用B需要jinja 2.6怎么办?这种情况下,每个应用可能需要各自拥有一套“独原创 2017-03-26 16:45:54 · 417 阅读 · 0 评论 -
Python中的self
self并不是Python中的保留字,但是在类的定义中,类的初始化函数中会经常使用self例如:>>>class Person():... def __init__(self,name)... self.name=name>>>hunter = Person('Louis')上面的代码做了一下工作:在内存中实例化一个新的对象,调用对象的__i原创 2016-02-01 17:43:58 · 598 阅读 · 0 评论
分享