Python3.x

来源:互联网 发布:a5淘宝客论坛 编辑:程序博客网 时间:2024/05/21 12:48
import urllib.request
import rereq = urllib.request.urlopen('http://www.imooc.com/course/list?c=python')buf = req.read()rs = buf.decode()listurl = re.findall(r'http://.+\.jpg', rs)print(listurl)i = 0for url in listurl:    f = open(str(i)+'.jpg', 'wb')    req = urllib.request.urlopen(url)    buf = req.read()    # print(buf)    f.write(buf)    i += 1截取的图片在项目的根目录下
慕课网用的2.x版本的python,我安装的3.x,有些差异。这个代码是评论区分享的,亲测有效,保存下来。
python3.5安装PyMySQLpip install PyMySQLhttps://pypi.python.org/pypi/PyMySQL#downloads下载文件测试import pymysqlconn = pymysql.connect(host='127.0.0.1', port=3306,user='root',passwd='123456',db='mysql',charset='UTF8')cur = conn.cursor()cur.execute("select version()")for i in cur:    print(i)cur.close()conn.close()
在终端ipython和pycharm上运行均正确
mysql启动命令:mysql -u root -p
输入密码
退出:exit
心好累啊,C,C++,JAVA都没有像Python这样分出2和3两个版本,还互不兼容。好多教学资源和开源代码都是2.x的,然而我想去的公司用3。虽然https://docs.python.org/3/whatsnew/3.0.html已经详细介绍了区别...考虑还是先学2吧。一定要坚持下去!
0 0