The bytes/str dichotomy in Python 3 - Eli Bendersky's website https://eli.thegreenplace.net/2012/01/30/the-bytesstr-dichotomy-in-python-3

Arguably the most significant new feature of Python 3 is a much cleaner separation between text and binary data. Text is always Unicode and is represented by the str type, and binary data is represented by thebytes type. What makes the separation particularly clean is that str and bytes can't be mixed in Python 3 in any implicit way. You can't concatenate them, look for one inside another, and generally pass one to a function that expects the other. This is a good thing.

import requests
import re
import time
from redis import Redis REDIS_HOST, REDIS_PORT, PASSWORD = '192.168.2.51', '6379', 'mypwd'
rds = Redis(host=REDIS_HOST, port=REDIS_PORT, password=PASSWORD) f, url_l, filter_replace_l = 'DISTINCT_url.txt', [], ['\n', '\t', ' ']
with open(f, 'r', encoding='utf-8') as fr:
for i in fr:
try:
for ii in filter_replace_l:
i = i.replace(ii, '')
rds.sadd('chk_url_all', i)
except Exception as e:
print(e) headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'}
while True:
try:
url = rds.spop('chk_url_all').decode('utf-8')
s = 'http://'
if s not in url:
url = '{}{}'.format(s, url)
print(url)
r = requests.get(url, headers=headers, timeout=50)
print(r.status_code)
except Exception as e:
print(e) 从redis取值结果为bytes type

The bytes/str dichotomy in Python 3的更多相关文章

  1. The bytes/str dichotomy in Python 3 [transport]

    reference and transporting from: http://eli.thegreenplace.net/2012/01/30/the-bytesstr-dichotomy-in-p ...

  2. 小白的Python之路 day1 Python3的bytes/str之别

    原文:The bytes/str dichotomy in Python 3 Python 3最重要的新特性大概要算是对文本和二进制数据作了更为清晰的区分.文本总是Unicode,由str类型表示,二 ...

  3. python2 与python3中最大的区别(编码问题bytes&str

    1,在python2.x 中是不区分bytes和str类型的,在python3中bytes和str中是区分开的,str的所有操作bytes都支持 python2 中 >>> s = ...

  4. Python3的bytes/str之别

    Python 3最重要的新特性大概要算是对文本和二进制数据作了更为清晰的区分.文本总是Unicode,由str类型表示,二进制数据则由bytes类型表示.Python 3不会以任意隐式的方式混用str ...

  5. python bytes/str

    http://eli.thegreenplace.net/2012/01/30/the-bytesstr-dichotomy-in-python-3/

  6. repr. str, ascii in Python

    repr和str a="Hello" print(str(a)) print(repr(a)) 结果: Hello 'Hello' 可以看出,repr的结果中多了左右两个引号. r ...

  7. python——TypeError: 'str' does not support the buffer interface

    import socket import sys port=51423 host="localhost" data=b"x"*10485760 #在字符串前加 ...

  8. Python学习之路-Day2-Python基础2

    Python学习之路第二天 学习内容: 1.模块初识 2.pyc是什么 3.python数据类型 4.数据运算 5.bytes/str之别 6.列表 7.元组 8.字典 9.字符串常用操作 1.模块初 ...

  9. Centos7 环境下 Python2.7 换成 Python3.7 运行 scrapy 应用所遇到的问题记录

    参考网友的安装过程 Linux系统Centos安装Python3.7 设置Python默认为Python3.7 mv /usr/bin/python /usr/bin/python.bak ln -s ...

随机推荐

  1. nginx做反向代理配置文件的例子

    worker_processes ; error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error ...

  2. RESTful API设计的简单例子

    代码承接简单服务器,修改 app.js const koa = require('koa'), app = new koa(), Router = require('koa-router'), rou ...

  3. docker 1-->docker machine 转载

    Docker Machine 是 Docker 官方编排(Orchestration)项目之一,负责在多种平台上快速安装 Docker 环境. Docker Machine 是一个工具,它允许你在虚拟 ...

  4. JAVA基础数组

    数组: 数组是一种容器 存储同一类型的一组数据(必须是 类型相同的一组数据) 定义数组的公式:(有两种) 1.静态定义      1)数据类型[ ] 数组名 = {元素1,元素2,元素3,元素4,元素 ...

  5. zip相关知识梳理(一)

    zip相关知识梳理(一) 经过对zip文件的长时间研究,对zip文件进行相关知识进行梳理,虽然网上很多牛人对其做了相关基础解析,但是对于特殊情况没有进行说明,比如超过4G的zip文件该以什么格式进行编 ...

  6. 搜索--P1219 N皇后

    题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...

  7. Luogu P1311 选择客栈

    暴力 我一开始做这道题先想到的就是暴力... 所以先说一下暴力的做法.首先在输入的时候讲花费小于P的位置标记下来,然后用两层循环枚举所有的两个客栈的组合方案.再用一层循环将两个客栈之间的位置扫一遍,如 ...

  8. 安迪的第一个字典(Andy's First Dictionary,Uva 10815)

    输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出.单 词不区分大小写. 样例输入: Adventures in Disneyland Two blondes were goin ...

  9. JAVA实现创建Excel表并导出(转发)

    <span style="font-family:Verdana, Arial, Helvetica, sans-serif;line-height:25.2px;background ...

  10. 入门系列(一) 微信小程序简介

    一.简介 1.目录结构 首先,我们使用微信公众平台提供的开发者工具,创建一个简单的小程序项目,观察项目的目录结构 不难看出,一个典型的微信小程序,通常包含一个描述整体的主体部分,以及一个描述页面的 p ...