Python
文章平均质量分 64
waiwai3
这个作者很懒,什么都没留下…
展开
-
python测试函数
测试函数是用于自动化测试,使用python模块中的unittest中的工具来测试附上书中摘抄来的代码:#coding=utf-8import unittestfrom name_function import get_formatted_nameclass NamesTestCase(unittest.TestCase): def test_first_last_name(self)原创 2017-08-23 22:51:00 · 10678 阅读 · 0 评论 -
python set转str,使用join()函数
>>> A = set(['a',b','c']) #set是无序不重复的>>> B = ','.join(A) #使用join将set中值连在一起,','单引号之间的是分隔符>>> print Ba,c,bset类型是无序不重复的,如果这里改成 A=set(['a',b','c','a']),print B的结果和上面也是一样的...原创 2018-06-18 10:23:25 · 17708 阅读 · 1 评论 -
python中获取当前日期
datetime:日期时间模块,提供多种方法操作日期和时间strftime:对日期时间格式化获取今天的日期,昨天的日期,格式化的日期>>> import datetime>>> today=datetime.date.today()>>> print today2018-01-17>>> formatted_today...原创 2018-01-17 23:23:57 · 149262 阅读 · 3 评论 -
python 连接cassandra数据库
cassandra比mysql快(其实这是一种错误的理解方式)点击打开链接但cassandra做group,order by操作时比较麻烦,看文章【cassandra的索引查询和排序】点击打开链接from cassandra.cluster import Clusterfrom cassandra.query import tuple_factoryfrom cassandra原创 2018-01-15 09:54:43 · 6418 阅读 · 2 评论 -
python中MySQLdb模块的用法
MySQLdb是用于python连接mysql数据库的接口1.导入MySQLdb模块:import MySQLdb2.打开mysql数据库连接:conn=MySQLdb.connect(host='localhost',user='root',passwd='password',port=3306,charset='utf-8')3.使用cursor()方法获取操作游标cu原创 2018-01-30 23:52:18 · 1097 阅读 · 0 评论 -
python 连接mysql数据库
#!/usr/bin/python# -*- coding: UTF-8 -*-import sysimport MySQLdbreload(sys)sys.setdefaultencoding('utf-8')db=MySQLdb.connect("服务器ip","username","password","database",charset='utf8'原创 2018-01-15 09:29:23 · 273 阅读 · 0 评论 -
python爬取糗事百科段子
代码参照 http://cuiqingcai.com/990.html原创 2017-11-23 21:53:26 · 455 阅读 · 0 评论 -
火车票上的星号暗藏玄机
代码来源http://www.freebuf.com/articles/database/143402.html的pi转载 2017-09-20 16:20:20 · 1004 阅读 · 0 评论 -
Django: TypeError topic() got an unexpected keyword argument 'topics_id'
urls.py#coding=utf-8'''定义learning_logs的URL模式'''from django.conf.urls import urlfrom . import viewsurlpatterns = [ #主页 url(r'^$',views.index,name='index'), #显示所有的主题 url(r'^topics/原创 2017-09-11 22:08:17 · 7785 阅读 · 6 评论 -
pygal画世界地图
#coding=utf-8import jsonimport pygal.maps.world#Pygal样式保存在模块style中,包括RotateStyle调整颜色和LightColorizedStyle加亮颜色#也可以写成from pygal.style import LightColorizedStyle, RotateStyleimport pygal.stylefrom c原创 2017-08-30 21:17:25 · 9536 阅读 · 1 评论 -
Django报错Exception Value: no such table xx
执行以下两步骤:python manage.py makemigration app_namepython manage.py migrate原创 2017-09-07 17:45:42 · 1880 阅读 · 2 评论 -
UnsupportedWheel: matplotlib.xxx.whl is not a supported wheel on this platform解决方案
安装画图工具matplotlib时报错:UnsupportedWheel: matplotlib-2.0.2-cp27-cp27m-win_amd64.whl is not a supported wheel on this platform.可在pip.log中查看报错日志:-------------------------------------------------------原创 2017-08-28 09:53:06 · 1779 阅读 · 2 评论 -
对文件中的ip取C段并去重写入文件
实现功能:对ip.txt中的ip取C段并去重,写入新的txt文件中#coding=utf-8#列表ipc用于存储对ip取前三位的C段结果ipc=[]with open("ip.txt","r") as f1: for line in f1: line=line.rstrip() line=line原创 2017-08-23 15:48:44 · 1206 阅读 · 0 评论 -
NameError: name 'FileNotFoundError' is not defined的解决方案
处理文件不存在使用FileNotFoundError来处理异常在python2.7中使用时提示:NameError: name 'FileNotFoundError' is not definedpython代码:报错:Traceback (most recent call last): File "J:/Python/821_03.py",原创 2017-08-21 22:24:01 · 22485 阅读 · 0 评论 -
pygal制图“AttributeError: 'NoneType' object has no attribute 'decode'”
最近在看书中的17章 使用Web Api17.2.2添加自定义工具提示# coding=utf-8import requestsimport pygalfrom pygal.style import LightColorizedStyle as LCS, LightenStyle as LS# 执行API调用并存储响应URL = 'https://api.github.com/s原创 2017-09-05 09:47:41 · 9352 阅读 · 20 评论 -
使用python的unittest测试类
题目:编写一个名为Employee 的类,其方法__init__() 接受名、姓和年薪,并将它们都存储在属性中。编写一个名为give_raise() 的方法,它默认将年薪增加5000美元,但也能够接受其他的年薪增加量。为Employee 编写一个测试用例,其中包含两个测试方法:test_give_default_raise() 和test_give_custom_raise() 。使用方法原创 2017-08-25 15:59:43 · 2326 阅读 · 0 评论 -
pandas.DataFrame.notnull返回非空值
>>> import pandas as pd >>> df = pd.read_csv('test.csv')>>> print df name id0 ZhangSan 1.01 LiSi 2.02 WangEr NaN3 WanZi 4.0>>&...原创 2018-06-19 17:38:02 · 39091 阅读 · 0 评论