我正在尝试将python2代码移植到python 3。
以下代码在python 2中正常工作
zones = [i.encode("ascii", "ignore").strip(" \"\'")
for i in resque_zone]
但是在Python 3中,这给了我著名的“需要一个类似字节的对象,而不是str”
line 194, in <listcomp>
for i in resque_zone]
TypeError: a bytes-like object is required, not 'str'
有人可以帮我吗
答案 0 :(得分:1)
如果要在apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: mysql
name: mysql
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.6
imagePullPolicy: IfNotPresent
env:
- name: MYSQL_ROOT_PASSWORD
value: root
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
ports:
- containerPort: 3306
name: mysql
protocol: TCP
volumeMounts:
- mountPath: /var/lib/mysql
name: data
volumes:
- name: data
emptyDir: {}
字符串上调用,则strip
的参数必须是bytes
对象。
bytes
或者在您zones = [i.encode("ascii", "ignore").strip(b" \"\'")
# ^
之前将其剥离:
encode