klearnpythonAPILinearRegressionfromsklearn.linear_modelimportLinearRegression#线性回归#module=LinearRegression()module.fit(x,y)module.score(x,y)module.predict(test)LogisticRegressionfromsklearn.linear_modelimportLogisticRegression#逻辑回
系统 2019-09-27 17:51:04 1922
学了一个多月的python,做了一个小程序:python实现简单成绩录入系统,实验一下menu部分fromtkinterimport*#这是一个python模块,python3中都有importtkinter.messagebox#这也是一个模块fromfile_readimportreadfromfile_writeimportwriteclassstudent_main():#定义一个学生类def__init__(self):self.name=''s
系统 2019-09-27 17:50:34 1922
阅读更多pipinstallpyecharts;会安装pyecharts-1.1.0画K线图kline1.py#coding:utf-8importos,sysfrompyechartsimportoptionsasoptsfrompyecharts.chartsimportKlineiflen(sys.argv)==2:code=sys.argv[1]else:print('usage:kline1.pycode')sys.exit(1)iflen(co
系统 2019-09-27 17:50:05 1922
记录三种添加cookie保持接口登录状态的方法,方便自己回顾。1.简单粗暴式。此方法比较小白,前提是已经通过fiddler抓包等方式拿到了cookie,然后直接塞进去。importrequeststrainsUrl='http://XXX.com/trains'headers={"Content-Type":"application/json;charset=UTF-8",}cookies={"XXXthor":"XXXXXX105a42"}prames=
系统 2019-09-27 17:49:54 1922
输入:s=‘happying’输出:s=‘gniyppah’方法1#使用字符串切片r=s[::-1]方法2#使用reducer=reduce(lambdax,y:y+x,s)方法3#使用递归函数#字符串s的倒序是,是s除去第一个字符的字符串的倒序加上第一个字符deffunc(s):iflen(s)<1:returnsreturnfunc(s[1:])+s[0]r=func(s)方法4#使用列表的reverse方法#reverse不是按照与字母顺序相反的顺序
系统 2019-09-27 17:49:53 1922
Python3注释确保对模块,函数,方法和行内注释使用正确的风格Python中的注释有单行注释和多行注释:Python中单行注释以#开头,例如::#这是一个注释print("Hello,World!")多行注释用三个单引号'''或者三个双引号"""将注释括起来,例如:1、单引号(''')#!/usr/bin/python3'''这是多行注释,用三个单引号这是多行注释,用三个单引号这是多行注释,用三个单引号'''print("Hello,World!")2、
系统 2019-09-27 17:49:52 1922
filter(function,sequence):对sequence中的item依次执行function(item),将执行结果为True的item组成一个List/String/Tuple(取决于sequence的类型)返回:复制代码代码如下:>>>deff(x):returnx%2!=0andx%3!=0>>>filter(f,range(2,25))[5,7,11,13,17,19,23]>>>deff(x):returnx!='a'>>>filt
系统 2019-09-27 17:49:44 1922
这里使用pipe代码如下:importtimefrommultiprocessingimportProcessimportmultiprocessingclassD:@staticmethoddeftest(pipe):whileTrue:foriinrange(10):pipe.send(i)time.sleep(2)@staticmethoddeftest2(pipe):whileTrue:print('test2value:%s'%pipe.recv
系统 2019-09-27 17:49:29 1922
原文链接:https://my.oschina.net/xiaocon/blog/199414finally关键字的意思是只要异常,到最后都会执行语句块。。。#!/usr/bin/pythonimporttimetry:f=file('poem.txt')whileTrue:line=f.readline()iflen(line)==0:breaktime.sleep(2)printline,finally:f.close()print'file.clos
系统 2019-09-27 17:49:21 1922
本文实例讲述了Python文件的读写操作。分享给大家供大家参考,具体如下:读写文件读取文件f=open('my_path/my_file.txt','r')#open方法会返回文件对象file_data=f.read()#通过read方法获取数据f.close()#关闭该文件首先使用内置函数open打开文件。需要文件路径字符串。open函数会返回文件对象,它是一个Python对象,Python通过该对象与文件本身交互。在此示例中,我们将此对象赋值给变量f。
系统 2019-09-27 17:49:16 1922