Fork me on GitHub

青禹小生

雁驰万里却作禽,鱼未得水空有鳞。 花开花落花不语,昨是昨非昨亦今。

导航

随笔分类 -  Python学习

conda 安装 graph-tool, 无需编译
摘要:1. 添加以下channels到~/.condarc 2. 安装graph-tool 3. 进入python terminal 检查是否安装成功 阅读全文

posted @ 2018-11-02 14:25 司徒道 阅读(5238) 评论(1) 推荐(0)

关于python的GIL
摘要:转自依云在知乎上的回答,链接为https://www.zhihu.com/question/27245271/answer/462975593 侵删。 python的多线程,其实不是真的多线程,它会通过GIL来控制线程,导致不管有多少个核,其实在同一时间只有一个线程在跑。 在python程序中调用c 阅读全文

posted @ 2018-09-04 12:27 司徒道 阅读(376) 评论(0) 推荐(0)

ubuntu服务器安装jupyter notebook, 并能够实现本地远程连接
摘要:1.terminal 敲击 pip3 install jupyter 2.terminal 敲击 jupyter notebook --generate-config 3.terminal 敲击 python3 python命令行里敲击 from notebook.auth import passw 阅读全文

posted @ 2018-01-04 16:16 司徒道 阅读(3039) 评论(0) 推荐(1)

利用百度地图API实现地址和经纬度互换查询
摘要:1 import json 2 import requests 3 4 5 def baiduMap(input_para): 6 headers = { 7 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit' 8 '/53... 阅读全文

posted @ 2018-01-02 16:02 司徒道 阅读(1346) 评论(0) 推荐(0)

批量更新python库
摘要:1 import pip 2 from subprocess import call 3 4 for dist in pip.get_installed_distributions(): 5 try: 6 call("pip install --upgrade " + dist.project_name, shell=True) 7 except Excepti... 阅读全文

posted @ 2017-10-09 17:48 司徒道 阅读(619) 评论(4) 推荐(0)

利用python在windows环境下爬取赶集网工作信息。
摘要:主要用到了多进程和多线程的知识,最后结果保存成csv文件格式,如有需要可改成数据库版本。 对用到的库做下简要介绍,具体请参考官方文档: xpinyin.Pinyin:将输入的中文转成拼音 concurrent.futures.ProcessPoolExecutor:多进程 concurrent.fu 阅读全文

posted @ 2017-06-11 21:41 司徒道 阅读(606) 评论(0) 推荐(0)

扔骰子
摘要:把一个骰子扔n次, n次朝上一面的点数和为s。 输入n, 打印出s的所有可能的值出现的概率。 1 from decimal import Decimal 2 3 def get_dice(): 4 # 一个骰子扔n次 5 times = input('please input an integer\ 阅读全文

posted @ 2017-04-24 20:29 司徒道 阅读(522) 评论(0) 推荐(0)

python 输入英语单词,查看汉语意思
摘要:# -*- coding:utf-8 -*- import urllib2 import lxml.html as HTML def get_wordmean(): url = 'http://www.iciba.com/' search = raw_input('search:') url += search headers = {'User-Agent':'... 阅读全文

posted @ 2017-04-11 20:32 司徒道 阅读(1201) 评论(0) 推荐(0)

爬取代理IP,并判断是否可用。
摘要:1 # -*- coding:utf-8 -*- 2 from gevent import monkey 3 monkey.patch_all() 4 5 import urllib2 6 from gevent.pool import Pool 7 8 import requests 9 import re 10 11 class SpiderProxy: 12 ... 阅读全文

posted @ 2017-03-26 13:49 司徒道 阅读(291) 评论(0) 推荐(0)

python 实现无序列表
摘要:1 # -*- coding:utf-8 -*- 2 class Node: 3 def __init__(self, initdata): 4 self.data = initdata 5 self.next = None 6 7 def getData(self): 8 return self.... 阅读全文

posted @ 2017-03-09 17:28 司徒道 阅读(746) 评论(0) 推荐(0)

python 实现剪刀石头布(三局两胜)
摘要:1 # -*- coding:utf-8 -*- 2 import random 3 4 # best of three 5 def finger_guess(): 6 rule = {1:'rock', 2:'paper', 3:'scissor'} 7 win_way = [['rock', 'scissor'], ['paper', 'rock'], ['s... 阅读全文

posted @ 2017-03-09 16:40 司徒道 阅读(2195) 评论(0) 推荐(0)

python 实现简单语音聊天机器人
摘要:'''思路:使用百度的文本转音频API,将结果保存成mp3格式,并用mp3play库播放该文件。''' 1 # -*- coding:utf-8 -*- 2 import sys 3 import requests 4 import json 5 import mp3play 6 import time 7 8 def talk(info): 9 appkey = "e... 阅读全文

posted @ 2017-03-09 16:39 司徒道 阅读(2997) 评论(0) 推荐(0)

visual studio code 安装python扩展
摘要:Ctrl+P 调出控制台,在控制台里输入ext install python,点击第一个安装 如果出现: visual studio code connect ETIMEDOUT 191.238.172.191:443,需要在用户设置里添加:"http.proxyStrictSSL": false 阅读全文

posted @ 2017-01-02 12:25 司徒道 阅读(2902) 评论(0) 推荐(0)

list内容按长度等分
摘要:这里需要导入 from more_itertools import chunked chunked(iterable, n) 将一个可迭代对象等分成n个list,第n个list的长度可能小于之前的。 阅读全文

posted @ 2016-11-25 15:53 司徒道 阅读(381) 评论(0) 推荐(0)

给定一个英文句子(一个只有字母的字符串),将句中所有单词变为有且只有首字母大写
摘要:输出: Python Is A Programming Language That Lets You Work Quickly And Integrate Systems More Effectively 阅读全文

posted @ 2016-11-22 21:42 司徒道 阅读(1190) 评论(0) 推荐(0)

range()和xrange()
摘要:range(): range([start,] stop[, step]) 如: range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] range()默认起始点为0 且range()返回的是一个list xrange()返回的是一个生成器,需要list()将其转换 但其性 阅读全文

posted @ 2016-11-21 20:37 司徒道 阅读(188) 评论(0) 推荐(0)