我有一段代码,如下所示(运行python 2.7.12):
self.config = ConfigParser()
self.config.read(self.config_file)其中self.config_file的类型是string,但是当在一个复杂得多的代码(带有py.test的python-selenium)中运行这段代码时,我会得到一个警告:
DeprecationWarning: You passed a bytestring as `filenames`. This will not work on Python 3. Use `cp.read_file()` or switch to using Unicode strings across the board.
self.config.read(self.config_file)在尝试创建一个小的代码示例时,我不再收到此警告。
也许有一个简单的方法来解决这个问题?
发布于 2019-04-11 13:58:40
您可以使用decode方法将字节解码为字符串:
self.config.read(self.config_file.decode())发布于 2019-04-11 14:01:20
错误有解决方案。使用以下命令将self.config_file参数更改为unicode
self.config.read(unicode(self.config_file,"utf-8"))https://stackoverflow.com/questions/55625428
复制相似问题