Вопрос

I'm getting this error on creating a string with arguments like "abcd%s"%(e) but I'm getting e by scraping a web page. Can anyone please tell me what is the best way to avoid this error.

I found other similar questions but they were using %20 in the url for which they need to replace %20 with %%20 which solved their problem. But my case is different. I tried encoding e but still getting same error.

ValueError: unsupported format character 'W' (0x57)
Это было полезно?

Решение

>>> "abcd%W"%(123)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unsupported format character 'W' (0x57) at index 5

Could something like this work for you instead?

>>> "abcd%W".replace('%W', str(123))
'abcd123'
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top