
python
harryhare
这个作者很懒,什么都没留下…
展开
-
python 标准输出重定向到文件后,文件为空
问题描述启动一个http server 然后把 标准输出的 log 重定向到 文件python server.py > log.txt 2>&1 &然后 tail -f log.txt 会发现一直时空的但是 如果把 server.py 换成 只有一行print 的文件, 则 输出文件是正常的print("test")解强制输出刷缓存加参数 -u...原创 2020-02-19 05:06:32 · 1611 阅读 · 0 评论 -
python import/package
示例projecthttps://github.com/harryhare/python_import_playground在不涉及包的情况下,引用其他文件直接 import 文件路径就可以包包和普通目录的区别只是包多了个__init__.py 文件。有了这个文件后,在import 时则可以用目录名,而不是直接引用文件名。同时 import 后,只有__init__.py 文件中定义...原创 2020-02-17 21:00:49 · 285 阅读 · 0 评论 -
python -m pip install --upgrade pip 报错
具体问题环境:windowspython3.6根据pip 的提示WARNING: You are using pip version 19.3.1; however, version 20.0.2 is available.You should consider upgrading via the 'python -m pip install --upgrade pip' comm...原创 2020-02-07 01:48:43 · 2139 阅读 · 1 评论 -
python 装饰函数
修饰函数的简单例子# # 错误写法# def warp(fun):# print("***")# fun()# print("***")## @warp# def myprint():# print(&a原创 2018-05-30 14:24:42 · 438 阅读 · 0 评论 -
python 的正则
# -*- coding: utf-8 -*-import re# match: 从字符串开始进行匹配x=re.match(r"(\d)\d*","123 1234 2345")print(type(x))print(x.group()) # 123print(x.groups()) # ()匹配的内容 ('1',)p=原创 2018-05-30 18:12:14 · 132 阅读 · 0 评论 -
编码
还没有搞明白,测试代码先放在这里。有一个地方要注意, 编码和文件格式是两个概念 文件格式大概有四类,分别对应notepad++encoding列表的四个 它们的区别是文件开头的字节utf 8空utf 8 bom\xef\xbb\xbfunicode be\xfe\xffunicode le\xfe\xffunicode 相关的还没有明白。...原创 2018-06-07 20:21:02 · 255 阅读 · 0 评论 -
python 备忘 (二)
1.字符串格式化 和r定义的字符串有format 和%两种格式化print("name:{name}".format(name="harryhare"))print(&qu原创 2018-05-31 20:32:02 · 155 阅读 · 0 评论 -
python pipenv 和 vitualenv 和venv
1.pipenvhttps://pypi.org/project/pipenv/#安装pip install pipenv #ubuntubrew install pipenv #mac #创建环境pipenv --threepipenv --two#安装包pipenv install packege_name#包依赖图pipenv graph#查看已经安装的包...原创 2018-06-10 16:54:40 · 1183 阅读 · 0 评论 -
python 3.6
mac 和 windows 上好像可以直接装,只有linux麻烦一些 官方地址: https://www.python.org/downloads/release/python-365/ 源码包地址: https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgzwget https://www.python.org/ftp/pyt...原创 2018-06-18 11:33:11 · 284 阅读 · 0 评论 -
pycharm 编译环境设置
mac针对某一projectpycharm-> preferences -> project-> 选择要改变的project右侧那个旁边有个⚙️,点击后选择showall然后增加解释器defaultFile -> default settings...原创 2018-11-05 15:26:57 · 3945 阅读 · 0 评论 -
md5 python/go
go前两段hash 的结果相同空的hash 结果并不为空,而是 d41d8cd98f00b204e9800998ecf8427esum 的作用比较奇怪1:其实只是把参数加到当前hash 值的前面作为结果输出,并不改变hash的状态。唯一参数不为空的情形是: 需要把每个hash块的值连起来.所以实际使用中几乎遇不到sum的参数不是nil的情况func test_hash(){ h:=...原创 2019-03-04 00:08:39 · 156 阅读 · 0 评论 -
python 函数相关
转自:https://www.cnblogs.com/AlwaysWIN/p/6202320.htmlfrom functools import reducefoo = [2, 18, 9, 22, 17, 24, 8, 12, 27]print (list(filter(lambda x: x % 3 == 0, foo)))#[18, 9, 24, 12, 27]print (...原创 2018-05-30 03:39:04 · 251 阅读 · 0 评论 -
python 的内置函数
1.__init__()和__new__() 初始化 https://www.cnblogs.com/qlshine/p/6049457.html 2.__name__ 函数名 https://www.cnblogs.com/superxuezhazha/p/5793536.html 3.__call__() 对象本身作为函数 https://www.cnblogs.com/superx...转载 2018-05-22 01:33:18 · 170 阅读 · 0 评论 -
python 中文
文件第一行或者第二行加入:#-*-coding:utf-8 -*-或者:#-*-coding:utf-8 -*-参考: https://www.cnblogs.com/KarryWang/p/3260858.html转载 2018-05-22 01:15:00 · 160 阅读 · 0 评论 -
python备忘
1.定长list定义x=[0]*10y=[1]*1002.字符和整数互转x=ord('a')y=chr(x+1)#y='b'z=str(1)#z='1'i=int(z)#i=1原创 2015-10-19 23:33:33 · 765 阅读 · 0 评论 -
python中使用xmlrpc
参考简介:http://xmlrpc.scripting.com/spec.html代码一:http://www.jb51.net/article/44515.htm代码二:http://www.cnblogs.com/coderzh/archive/2008/12/03/1346994.html转载 2015-07-26 20:37:36 · 804 阅读 · 0 评论 -
python 爬虫及相关
爬虫: http://python.jobbole.com/81344/python的urllib urllib2 httplib: http://blog.youkuaiyun.com/dolphin_h/article/details/45296353转载 2017-02-08 19:25:49 · 303 阅读 · 0 评论 -
error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat)
报错: error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat).环境: python2.7安装ipython出错 window7 vs2012解决方案: 下载安装Microsoft Visual C++ Compiler for Python 2.7 https://www.microsof原创 2017-02-21 20:19:01 · 2912 阅读 · 0 评论 -
python pillow
http://www.jianshu.com/p/81f774d98562转载 2017-12-10 12:00:42 · 273 阅读 · 0 评论 -
简易服务器
python -m http.server 80转载 2017-12-19 22:47:02 · 174 阅读 · 0 评论 -
mac pip
https://pip.readthedocs.io/en/stable/installing/ https://www.zhihu.com/question/50470150?sort=created转载 2018-05-18 16:09:59 · 405 阅读 · 0 评论 -
python 读文件的字符编码问题
参考:https://blog.youkuaiyun.com/zhangyunfei_happy/article/details/47169939 关键点在于r 打开时,encode 要直接作为参数 如果用其他的encode 方式,那么打开文件时需要用rb#方法一file=open('xxx.csv','r',encoding='UTF-8')#方法二file=codecs.open('xxx....原创 2018-05-20 19:47:55 · 199 阅读 · 0 评论 -
python plot 柱状图
1.plot https://www.cnblogs.com/liutongqing/p/6985805.html 2.柱状图 http://www.jb51.net/article/130622.htm转载 2018-05-20 19:56:01 · 731 阅读 · 0 评论 -
python 多进程编程
http://python.jobbole.com/82045/转载 2015-09-11 21:39:36 · 787 阅读 · 0 评论