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. Android Measure 体系简单总结

    Android对View的测量是半协商半强制半模糊半具体的. 测量过程中的两套尺寸体系:  [半强制] ParentView**约束ChildView: **MeasureSpec(通过measure ...

  2. MFC_2.7 树控件的基本使用

    树控件的基本使用 1.添加控件设置变量绑定 2.添加数据 HTREEITEM RootNode1 = m_TreeCtrl.InsertItem(L"北京"); HTREEITEM ...

  3. VR虚拟红包的技术实现

    2017年1月20日,腾讯发布消息称将推出Q-Glass,除了一般VR眼镜的标配功能外,Q-Glass还能实现眨眼抢红包.听起来是不是很酷炫?上市时间可要在10年后.不过,2016年底支付宝首推AR实 ...

  4. 100 道 Linux 笔试题,能拿 80 分就算大神!

    本套笔试题共100题,每题1分,共100分.(参考答案在文章末尾) 1. cron 后台常驻程序 (daemon) 用于: A. 负责文件在网络中的共享 B. 管理打印子系统C. 跟踪管理系统信息和错 ...

  5. gym101343 2017 JUST Programming Contest 2.0

    A.On The Way to Lucky Plaza  (数论)题意:m个店 每个店可以买一个小球的概率为p       求恰好在第m个店买到k个小球的概率 题解:求在前m-1个店买k-1个球再*p ...

  6. 模板—AC自动机

    #include<iostream> #include<cstdio> #include<cstring> using namespace std; struct ...

  7. eBPF监控工具bcc系列五工具funccount

    eBPF监控工具bcc系列五工具funccount funccount函数可以通过匹配来跟踪函数,tracepoints 或USDT探针.例如所有以vfs_ 开头的内核函数. ./funccount ...

  8. 前端安全 xss

    整体的 XSS 防范是非常复杂和繁琐的,不仅需要在全部需要转义的位置,对数据进行对应的转义.而且要防止多余和错误的转义,避免正常的用户输入出现乱码. 虽然很难通过技术手段完全避免 XSS,但可以总结以 ...

  9. 『 Luogu P3205 』 HNOI2010 合唱队

    解题思路 设置两个二维数组 $f$ 和 $g$,含义如下. $f[l][r]$ 表示在期望得到的队形中 $l\rightarrow r$ 这段区间初始队形排列的方案数,并且最后一个加入进去的是第 $l ...

  10. FileWriter实现从一个文件中读取内容并写到另一个文件中

    FileWriter和FileOutputStream都是向文件写内容,区别是前台一次写一个字符,后者一次写一个字节 package com.janson.day20180827; import ja ...