我是python的新手...最近我已迁移到Py 3.6.8。这段代码在Python 2.7中正常工作:
#!/usr/bin/env python
from __future__ import print_function
import json
import sys
import os
import re
import subprocess
import datetime
from glob import glob
import boto3
class VariableCollector:
def getall(self):
collected_vars = {}
for name in dir(self):
#name = name.decode()
if name.startswith("get_"):
debug("VariableCollector - Calling: %s" % (name))
method = getattr(self, name)
collected_vars[name] = method()
collected_vars[name + ":no_quotes"] = collected_vars[name].replace("'","")
debug("Function: [%s] Value: [%s]" % ( name, collected_vars[name] ))
return collected_vars
升级到3.6.8后,我得到了:
File "./process.py", line 21, in getall
collected_vars[name + ":no_quotes"] = collected_vars[name].replace("'","")
TypeError: a bytes-like object is required, not 'str'