- 博客(105)
- 收藏
- 关注
原创 生成器中yield 与 return
这里用的是python 3.6可以用yield定义生成器,生成器保存的是算法,每迭代一次,返回一个yield后的值,直到遇到StopIteration,迭代完成,即next指向StopIteration,这个生成器不能再次被迭代初学不能理解yield的时候,就把yield看成print,只不过print是返回给人看的,yield是返回给机器的但我们在用yield定义生成器的时候,...
2017-08-08 10:24:49
506
原创 centos7 python3 安装matplotlib 和 scikit-learn
scikit-learn直接pip3 install scikit-learn能安装成功,但是import sklearn ,就会报错ImportError: no module named '_bz2' 解决办法yum install bzip2-devel matplotlib在centos系统下,导入matplotlib时,出现ImportErro...
2017-07-08 18:54:45
1107
原创 python字符串 decode 和 encode
# str encode 后返回bytes,byts decode后返回stra = '你好'a1 = a.encode('utf-8') # b'\xe4\xbd\xa0\xe5\xa5\xbd'a2 = a.encode('gbk') # b'\xc4\xe3\xba\xc3'a1.decode('utf-8') # 你好a2.decode('gbk')...
2017-06-30 11:26:31
234
原创 Sublime text2[Decode error - output not utf-8] 完美解决方法
打开build system , 找不到build system文件可以新建一个保存,看看文件在哪里 { "cmd": ["D:/Python36/python3.exe","-u","$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "sel
2017-06-30 11:20:38
222
原创 centos 下安装python3,pycharm
先安装yum安装openssl-devel ,否则pip不能安装,或会出现ssl错误查看openssl安装包,发现缺少openssl-devel包 [root@localhost ~]# rpm -aq|grep openssl openssl-0.9.8e-20.el5 openssl-0.9.8e-20.el5 [root@localhost ~]#yum安装open...
2017-06-23 21:18:14
306
原创 转 windows下python3安装Twisted
Python Extension Packages for Windows去上面地址下载你对应版本cp35的whl,注意,虽然你系统是64位,但要看清你python版本是32还是64位的,再下载对应的win32或者amd64文件安装wheelpip install wheel进入.whl所在的文件夹,执行命令即可完成安装pip install 带后缀的完整文件...
2017-06-20 17:38:37
304
原创 python实现单向链表(python27)
# encoding:utf-8class NodeException(Exception): def __init__(self, value): self.value = value def __str__(self): return repr(self.value)class Link...
2017-06-08 20:48:49
112
原创 转UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position
Python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128),python没办法处理非ascii编码的,此时需要自己设置将python的默认编码,一般设...
2017-05-31 10:00:21
216
原创 阿里云公网IP不能被访问
弄了个最小配置的阿里云服务器ECS,也装好nginx,配置好,本地能访问,就是用公网IP访问不了,发现原来是有个叫安全组的东西要设置,进入云服务器管理控制台,找到安全组,点右边的配置规则 他原本是有几个入方向的规则,和一个出方向的规则,我是把原来入方向的所有规则都删了,,点添加安全组规则,可以设置 我就设置能访问全部端口...
2017-05-27 09:50:02
524
原创 from bs4 import BeautifulSoup 报错
导入Beautifulsoup 报错 AttributeError: 'module' object has no attribute '_base' D:\Python27\Lib\site-packages\html5lib\treebuilders将base.py前面加了一个_,改为_base.py,base.pyc改为_base.pyc...
2017-05-26 19:48:00
651
原创 python requests 乱码解决
r = requests.get(login_page)print r.text 会显示中文乱码 r.encoding = r.apparent_encoding这样OK
2017-05-25 13:41:55
133
原创 ubuntu上python安装mysql和postgresql
先update一下$ sudo apt-get update 安装mysql$ sudo apt-get install mysql-server mysql-client$ sudoapt-get installlibmysqld-dev$ pip install MySQL-python安装postgresql$ sudo apt-get install po...
2016-09-29 22:25:42
119
原创 ppostgres 命令
链接postgresql psql -U david -d test -h 127.0.0.1 -p 5432 用管理员链接 psql -U postgres -d postgres -h 127.0.0.1 -p 5432建数据库 CREATE DATABASE test OWNER david;显示表 \d显示数据库 \l推出 \q...
2016-09-27 14:07:38
185
原创 (收藏)A Guide to Python's Magic Methods
from http://www.rafekettler.com/magicmethods.html A Guide to Python's Magic MethodsRafe KettlerCopyright © 2012 Rafe KettlerVersion 1.17A PDF version of this guide can be obtained from ...
2016-09-27 09:40:33
325
原创 nginx转发404给django
要设置图片缓存,所以图片都是经过nginx转的, location /media/ { expires 7d; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate";...
2016-09-22 16:59:15
425
原创 django-haystack2.0.1 commands 文档
Management CommandsHaystack comes with several management commands to make working with Haystack easier.clear_indexThe clear_index command wipes out your entire search index. Use with cautio...
2016-08-30 09:44:57
176
原创 postgresql设置远程访问
postgresql默认情况下,远程访问不能成功,如果需要允许远程访问,需要修改两个配置文件,说明如下:cd /etc/postgresql-9.4 (这个目录可能不同)1.postgresql.conf将该文件中的listen_addresses项值设定为“*”2.pg_hba.conf在该配置文件的host all all 127.0.0.1/32 md5行下添加以下...
2016-08-11 10:22:32
118
原创 linux服务的启动
最近用到postgresql,可是不知道怎么启动,原来linux的启动服务都差不多例如service nginx start (status | stop | restart) service postgresql-9.3 start (status | stop | restart) 没有service命令的如下 sudo /etc/init.d/postgre...
2016-08-11 10:04:13
137
原创 django userena 使用
参考 http://docs.django-userena.org/en/latest/installation.html#required-settings 我用的是django1.9.7, userena2.0.1原来文档的顺序跑不出来, 我跑出来的顺序是1 pip install django-userena 2 Required settings...
2016-07-12 17:30:36
182
原创 pip 安装源
pipy国内镜像目前有: http://pypi.douban.com/ 豆瓣http://pypi.hustunique.com/ 华中理工大学http://pypi.sdutlinux.org/ 山东理工大学http://pypi.mirrors.ustc.edu.cn/ 中国科学技术大学 对于pip这种在线安装的方式来说,很方便,但网络不稳定的话很要命...
2016-07-12 15:40:26
94
原创 Django uwsgi nginx 配置
全部安装好之后 不用python manage.py runserver 而是用uwsgi uwsgi.ini命令, 其中uwsgi.ini是写的uwsgi配置文件,[uwsgi]socket = 127.0.0.1:3031chdir = /home/david/projectwsgi-file = xxx/wsgi.pyprocesses = 4threa...
2016-06-29 16:22:48
298
原创 .gitignore过滤文件
利用.gitignore过滤文件,如编译过程中的中间文件,等等,这些文件不需要被追踪管理。现象:在.gitignore添加file1文件,以过滤该文件,但是通过git status查看仍显示file1文件的状态。原因:在git库中已存在了这个文件,之前push提交过该文件。.gitignore文件只对还没有加入版本管理的文件起作用,如果之前已经用git把这些文件纳入了版本库...
2016-05-17 17:21:25
251
原创 从postgresql中 导数据到 mysql
从postgres中导出数据到csv中1 用postgres用户(root)登录postgresql2 建一个csv文件,并 chmod 7773 在原数据中修改----title中的;改成:(有;的标题在导出到csv中时会被拆分成两列)update article_article set title = 'China’s Copycats: Online vs. Offline....
2016-04-21 11:13:17
499
原创 用python把postgresql中的表内容复制到mysql中
postgresql中的表和mysql中的表结构不一样,过程中做点转换,特别是datetime的insert还有activated 字段在原表中是布尔型,mysql表中是tinyint型 import psycopg2import MySQLdbimport datetime, timepsycopg2_conn = psycopg2.connect(...
2016-03-31 14:53:22
875
原创 laravel 5.2 发邮件,怎么查看log
我是用的qq邮箱1) 开通qq邮箱的smtp服务,在邮箱的设置中,开通之后会得到一个密码,记下来2) 编辑laravel项目目录下的.env文件 vim .envMAIL_DRIVER=smtpMAIL_HOST=smtp.qq.comMAIL_PORT=25MAIL_USERNAME=123456789@qq.comMAIL_PASSWORD=hzppuevkhr...
2016-03-24 14:05:56
245
原创 laravel Django 对比
之前是用Django,现在需要用Laravel,其实一开始我是拒绝的,我不怎么喜欢php,写惯了python再写php老忘记写分号,还要经常对花括号,引用不是用.而是用->或=>,变量还要加个$, ...... 总之各种细节真是草尼玛, 工作中要用也没办法 或许习惯了就好点吧, 他们都是MVC框架 Laravel 对比 Dja...
2016-03-22 16:40:10
1201
原创 bootstrap sample
http://getbootstrap.com/components/# bootstrap 可以这样居中,刚发现阿<div class="col-sm-offset-2 col-sm-8">
2016-03-22 10:40:11
674
原创 laravel5.2 修改已有的表(之后在文档中发现另一个方法)
比如我有一个imgs表,现在在这个表中添加一个votes字段 php artisan make:migration add_votes_to_imgs_table --table=imgs 然后修改生成的migration文件 public function up() { Schema::table('imgs', function (Bl...
2016-03-14 16:50:08
150
原创 numpy关键点
axis >>> b = np.arange(12).reshape(3,4)>>> barray([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]])>>>>>> b.sum(axis=0) ...
2016-02-24 10:36:27
77
原创 百度统计 事件跟踪
有一个需求,就是统计页面上图片的点击,我发现百度统计中事件跟踪可以用,缺点的是数据出来要延迟几小时先安装百度统计的代码,怎么按转网上有,不说了 比如我要给我页面上的class 为sponsorlink 的 链接加上统计,在页面的js中加这段代码 $('.sponsorlink').on('click', function(){ v...
2016-01-15 10:43:00
589
原创 linux 定时任务 crontab
具体crontab内容参见http://blog.youkuaiyun.com/zwhfyy/article/details/34065187 ubuntu 重启crontabsudo service cron restart 不是ubuntu版本的重启命令$ service crond restart 我有个需求是根据时间自动发布文章, 但django环境又是用了vir...
2016-01-05 11:22:10
110
原创 python 记录log到文件
import logging logger = logging.getLogger("loggingmodule.NomalLogger") handler = logging.FileHandler("/home/david/one.log") formatter = logging.Formatter("[%(levelname)s][%(fun...
2015-12-18 15:49:42
441
原创 My sql 不能接连
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)而且又不能重启mysqlsudo service mysql restart 网上有什么ln 没用解决杀进程 重启ps -A |grep mysqld k...
2015-12-10 10:48:44
160
原创 解决同一页面jQuery多个版本冲突
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="utf-8" /> <title>jQuery测试页-111cn.net</titl
2015-12-04 16:01:22
185
原创 通过父元素 加css 类
/*a.detail_link { background-color: #7ccef3; padding: 5px 15px; color: #fff; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; }a.detail_link:hover { background-color: #00...
2015-11-12 17:37:41
118
原创 mysql操作
进入mysql命令行mysql -h localhost -u root -p 1.导出数据库(sql脚本) mysqldump -uroot -p db_name > test_db.sql 2.mysql导出数据库一个表 mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名 mysqldump -u wcnc -p test_db...
2015-11-02 13:42:00
79
原创 django 几条命令
杀manage.py进程 : ps -ef | grep manage.py|grep -v grep|awk '{print $2}'|xargs kill -9启动 : python manage.py runfcgi host=127.0.0.1 port=8090 启动fastcgi php-cgi -b 127.0.0.1:9000...
2015-09-23 14:25:30
74
原创 jquery ajax, django的sample
通过ajax向django发请求 代码片段 $("#id_article_1_load_button, #id_article_2_load_button, #id_article_3_load_button, #id_article_4_load_button").click(function() { id_array = this.id.split("_")...
2015-09-23 09:56:47
130
原创 virtualenv以及 建立alias
有人说:virtualenv、fabric 和 pip 是 pythoneer 的三大神器。不管认不认同,至少要先认识一下,pip现在倒是经常用到,virtualenv第一次听说,不过,总得尝试一下吧。 一、安装pip install virtualenv因为我已经安装了pip,那么就直接用pip来安装了,简单方便。其它的安装方式请参考官方网站:http:...
2015-09-07 22:45:35
312
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人