python-3.5

how to downgrade python3.8.10 to 3.5.6 on ubuntu via the terminal?

how to downgrade python3.8.10 to 3.5.6 on ubuntu via the terminal? Question: In order to install older version of keras, tensorflow 1.10.0 is needed. That should solve compatibility issues with an algorithm I am trying to run. TO be able to install these older versions of tensorflow and keras and older version of python is …

Total answers: 1

Python request SyntaxError: invalid syntax

Python request SyntaxError: invalid syntax Question: I have written a Python3.7.1 code, and I need to run it in Python3.5 (because I have to run it from Raspberry), an error shows up: teams = requests.get(f’http://api.football-data.org/v2/competitions/{league}/standings’, headers=headers, timeout = 10).json() SyntaxError: invalid syntax The error appears on the first comma (…standings’, headers…) I suppose this is …

Total answers: 1

module 'numpy' has no attribute 'dtype'

module 'numpy' has no attribute 'dtype' Question: When importing sklearn datasets eg. from sklearn.datasets import fetch_mldata from sklearn.datasets import fetch_openml I get the error Traceback (most recent call last): File “numbers.py”, line 1, in <module> from sklearn.datasets import fetch_openml File “/anaconda2/envs/numbers/lib/python3.5/site-packages/sklearn/__init__.py”, line 64, in <module> from .base import clone File “/anaconda2/envs/numbers/lib/python3.5/site-packages/sklearn/base.py”, line 11, in <module> …

Total answers: 2

How to resume file download in Python 3.5?

How to resume file download in Python 3.5? Question: I am using python 3.5 requests module to download a file using the following code, how to make this code “auto-resume” the download from partially downloaded file. response = requests.get(url, stream=True) total_size = int(response.headers.get(‘content-length’)) with open(file_path + file_name, “wb”) as file: for data in tqdm(iterable = …

Total answers: 1

Why when movex is defined after assignment does python 3.5 return UnboundLocalError: local variable 'movex' was referenced before assignment

Why when movex is defined after assignment does python 3.5 return UnboundLocalError: local variable 'movex' was referenced before assignment Question: So I’m following a pdf on game development with Python and pygame and I’m making a puzzle where blocks in the pygame window move randomly to generate a puzzle it runs up until it moves …

Total answers: 1

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) Question: I’m trying to execute a Python script, but I am getting the following error: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) I’m using python 3.5.2 on a Linux Mint 18.1 Serena OS Can someone tell me why this happens, …

Total answers: 19

Convert a number using atof

Convert a number using atof Question: In Python 3.5, I’d like to convert a German number string to a float using locale.atof with the following code: import locale from locale import atof locale.setlocale(locale.LC_ALL, ‘de_DE’) number = atof(‘17.907,08’) However, this raises a ValueError: ValueError: could not convert string to float: ‘17.907.08’ Why? Isn’t this exactly what …

Total answers: 3

How to throw exception from mocked instance's method?

How to throw exception from mocked instance's method? Question: This demo function I want to test is pretty straight forward. def is_email_deliverable(email): try: return external.verify(email) except Exception: logger.error(“External failed failed”) return False This function uses an external service which I want to mock out. But I can’t figure out how to throw an exception from …

Total answers: 2

correctly override __new__ in python3

correctly override __new__ in python3 Question: So I am trying to override __new__ and let it exist as a factory to create derived instances. After reading a bit on SO, I am under the impression that I should be calling __new__ on the derived instance as well. BaseThing class BaseThing: def __init(self, name, **kwargs): self.name …

Total answers: 1

Python behaves weird with piped input

Python behaves weird with piped input Question: I’m having trouble reading input from a .txt file within a python program due to some weird behavior in my code. I’m running my python script like this: python3 file.py < input.txt My python file (file.py) looks like this: inDATA = ” for i in range(7): tmp = …

Total answers: 1