Top "Python-3.x" questions

For questions about Python programming that are specific to version 3+ of the language.

Convert bytes to a string

I'm using this code to get standard output from an external program: >>> from subprocess import * >>&…

python string python-3.x
Best way to convert string to bytes in Python 3?

There appear to be two different ways to convert a string to bytes, as seen in the answers to TypeError: …

python string character-encoding python-3.x
How to install pip with Python 3?

I want to install pip. It should support Python 3, but it requires setuptools, which is available only for Python 2. How …

python python-3.x pip package setuptools
How to return dictionary keys as a list in Python?

In Python 2.7, I could get dictionary keys, values, or items as a list: >>> newdict = {1:0, 2:0, 3:0} >>> …

python python-3.x list dictionary python-2.x
TypeError: a bytes-like object is required, not 'str' when writing to a file in Python3

I've very recently migrated to Py 3.5. This code was working properly in Python 2.7: with open(fname, 'rb') as f: lines = […

python python-3.x string file byte
Print multiple arguments in Python

This is just a snippet of my code: print("Total score for %s is %s ", name, score) But I want …

python printing python-3.x arguments
How do I use raw_input in Python 3

import sys print(sys.platform) print(2**100) raw_input() I am using Python 3.1 and can't get the raw_input to "freeze" …

python python-3.x
How can I represent an 'Enum' in Python?

I'm mainly a C# developer, but I'm currently working on a project in Python. How can I represent the equivalent …

python python-3.x enums
Using Python 3 in virtualenv

Using virtualenv, I run my projects with the default version of Python (2.7). On one project, I need to use Python 3.4. …

python python-3.x virtualenv
How can I read inputs as numbers?

Why are x and y strings instead of ints in the below code? (Note: in Python 2.x use raw_input(). …

python python-3.x python-2.7 input int