Questions tagged [python-3.x]

DO NOT USE UNLESS YOUR QUESTION IS FOR PYTHON 3 ONLY. Always use alongside the standard [python] tag.

Python is a widely-used, interpreted, object-oriented, and high-level programming language with dynamic semantics, used for general-purpose programming. It was created by Guido van Rossum, and first released on February 20, 1991. Python 3 is the latest version of the Python programming language, first released on December 3rd, 2008. It features simplifications and improvements to the syntax of the language. Some of these changes are backwards incompatible, and therefore Python 3 has its own tag.

Although Python 3 is now the recommended and supported version of the language, some users still remain on version 2.7 for various reasons. If you start new projects or begin to learn Python, version 3 is now the recommended target under normal circumstances:

Python 3 is strongly recommended for any new development. As of January 2020, Python 2 has reached End Of Life status, meaning it will receive no further updates or bugfixes, including for security issues. Many frameworks and other add on projects are following a similar policy. As such, we can only recommend learning and teaching Python 3.

One of the main differences is in the print statement.

Python 2:

print "Hello World"

Python 3:

print("Hello World")

For more information on the differences, see Porting Python 2 Code to Python 3.

For information on Python in general, visit the main Python tag wiki.


Tagging recommendation:

Use the tag for all Python related questions. If you believe your question includes issues specific to the incompatible Python 2.x or Python 3.x, in addition to the main tag, use or . If you believe your question may be even more specific, you may include a version specific tag, such as .

Please do not mix (or a more specific tag such as ) and (ditto) unless you are specifically asking a question about an interoperability problem between versions.

Python Free Tutorials

Python Online Books

Python API Reference

Python Online IDE

Python Package Index

341062 questions
36
votes
1 answer

Map object has no len() in Python 3

I have this Python tool written by someone else to flash a certain microcontroller, but he has written this tool for Python 2.6 and I am using Python 3.3. So, most of it I got ported, but this line is making problems: data = map(lambda c: ord(c),…
user3219624
  • 533
  • 1
  • 4
  • 7
36
votes
5 answers

How to add a cookie to the cookiejar in python requests library

I am trying to add a cookie to an existing cookiejar using the python requests 1.2.3 library. Every time I add the new cookie, the data in the jar is munged for the new cookie. Keys missing, Values missing or matched to incorrect Keys. I'm not…
fat fantasma
  • 7,483
  • 15
  • 48
  • 66
36
votes
3 answers

How can I more easily suppress previous exceptions when I raise my own exception in response?

Consider try: import someProprietaryModule except ImportError: raise ImportError('It appears that is not installed...') When run, if someProprietaryModule is not installed, one sees: (traceback data) ImportError:…
Hammerite
  • 21,755
  • 6
  • 70
  • 91
36
votes
4 answers

What command to use instead of urllib.request.urlretrieve?

I'm currently writing a script that downloads a file from a URL import urllib.request urllib.request.urlretrieve(my_url, 'my_filename') The docs urllib.request.urlretrieve state: The following functions and classes are ported from the Python 2…
Marcus
  • 463
  • 1
  • 4
  • 5
36
votes
5 answers

Python 3: EOF when reading a line (Sublime Text 2 is angry)

while True: reply = input('Enter text') if reply == 'stop': break print(reply.upper()) The result was: Enter text:Traceback (most recent call last): File "C:\PythonProjects\5.py", line 2, in reply = input('Enter…
Kifsif
  • 3,477
  • 10
  • 36
  • 45
35
votes
4 answers

Why does itertools.permutations() return a list, instead of a string?

Why does itertools.permutations() return a list of characters or digits for each permutation, instead of just returning a string? For example: >>> print([x for x in itertools.permutations('1234')]) >>> [('1', '2', '3', '4'), ('1', '2', '4', '3'),…
kennysong
  • 2,044
  • 6
  • 24
  • 37
35
votes
3 answers

Is there any working memory profiler for Python3

In Python 2 there's a couple of tools but everything seems to be old and out-of-dated. I've found PySizer and Heapy but everything seems to be Python2 oriented and would take a lot of effort to port. objgraph is interesting but still not a fully…
35
votes
7 answers

How do I install pip for python 3.8 on Ubuntu without changing any defaults?

I'm trying to install pip for Python 3.8 on an Ubuntu 18.04 LTS. I know this has been asked way too many times. But those questions do not concern keeping Ubuntu's defaults specifically. And the answers on those questions either don't work or go…
Qumber
  • 13,130
  • 4
  • 18
  • 33
35
votes
2 answers

type hint returns NameError: name 'datetime' not defined

I have this function below; def time_in_range(start, end, x): """Return true if x is in the range [start, end]""" if start <= end: return start <= x <= end else: return start <= x or x <= end The function parameters are…
user3848207
  • 3,737
  • 17
  • 59
  • 104
35
votes
5 answers

How can I set an attribute in a frozen dataclass custom __init__ method?

I'm trying to build a @dataclass that defines a schema but is not actually instantiated with the given members. (Basically, I'm hijacking the convenient @dataclass syntax for other purposes). This almost does what I want: @dataclass(frozen=True,…
Sasgorilla
  • 2,403
  • 2
  • 29
  • 56
35
votes
6 answers

How can I solve " module 'pandas' has no attribute 'scatter_matrix' " error?

I'm trying to run pd.scatter_matrix() function in Jupyter Notebook with my code below: import matplotlib.pyplot as plt import pandas as pd # Load some data iris = datasets.load_iris() iris_df = pd.DataFrame(iris['data'],…
spidermarn
  • 959
  • 1
  • 10
  • 18
35
votes
3 answers

Difference between Enum and IntEnum in Python

I came across a code that looked like this: class State(IntEnum): READY = 1 IN_PROGRESS = 2 FINISHED = 3 FAILED = 4 and I came to the conclusion that this State class could inherit the Enum class in the same way. What does…
Yuval Pruss
  • 8,716
  • 15
  • 42
  • 67
35
votes
2 answers

Visual Studio Code Python debugging "Exception has occurred SystemExit"

I've been using Visual Studio code for a long time with the Python extension. Currently I have Visual Studio Code version 1.27.2, Python extension "ms-python.python" version 2018.8.0, python version 3.6.6, hosted by a Windows 10 1803 Enterprise…
35
votes
8 answers

ValueError: Expected 2D array, got 1D array instead:

While practicing Simple Linear Regression Model I got this error, I think there is something wrong with my data set. Here is my data set: Here is independent variable X: Here is dependent variable Y: Here is X_train Here Is Y_train This is error…
danyialKhan
  • 697
  • 2
  • 8
  • 12
35
votes
7 answers

pylint false positive E0401 import errors in vscode while using venv

I created a venv using python3.6 on my mac os in this folder /Users/kim/Documents/Apps/PythonApps/python36-miros-a3 I ran a pip install pylint after I activated the virtual env My workspace is in /Users/kim/Documents/Apps/WebApps/miros-a3 Inside my…
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282
1 2 3
99
100