Skip to content
Advertisement

Tag: python-3.x

Python popen() – communicate( str.encode(encoding=”utf-8″, errors=”ignore”) ) crashes

Using Python 3.4.3 on Windows. My script runs a little java program in console, and should get the ouput: This leads to a normal ‘UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position 135: character maps to < undefined>’. Now I want to ignore errors: This leads to a more interesting error I found no help for using google: TypeError:

How to set class attribute with await in __init__

How can I define a class with await in the constructor or class body? For example what I want: or example with class body attribute: My solution (But I would like to see a more elegant way) Answer Most magic methods aren’t designed to work with async def/await – in general, you should only be using await inside the dedicated

Generator as function argument

Can anyone explain why passing a generator as the only positional argument to a function seems to have special rules? If we have: This works, as expected. This does not work, as expected. This works, as expected This works, but I don’t understand why. Shouldn’t it fail in the same way as 2) Answer Both 3. and 4. should be

Logging module not working with Python3

I am having issues with the standard logging module. If I open a python2.7 shell and import logging everything works fine: But if I open a python3.4 shell and import logging I get the following error: I have no idea what the problem is and can’t seem to find anyone else who has had the same issue. Answer You seem

Why round off of 0.500000 in python differs from 45.500000 using ‘%.0f’?

Recently, I learned art of string formatting in Python 2.7. I decided to play with floating point numbers. Came across an awkward looking solution, as written below. BUT Please help me understand, why this behavior is shown by %f. Answer The internal implementation for the %.0f string format uses a round-half-even rounding mode. In Python 2, the round() function uses

Advertisement