python-3.10

PySpark loading from MySQL ends up loading the entire table?

PySpark loading from MySQL ends up loading the entire table? Question: I am quite new to PySpark (or Spark in general). I am trying to connect Spark with a MySQL instance I have running on RDS. When I load the table like so, does Spark load the entire table in memory? from pyspark.sql import SparkSession …

Total answers: 1

Django FileDescriptor in settings

Django FileDescriptor in settings Question: In my Django project, I want to use the MaxMind db file to acquire information about IP-addresses. The file takes up to 90 megabytes. I expect about 50 requests per second and also the application will be hosted on the Gunicorn with 3 workers. So, Will I meet the limits …

Total answers: 1

Run event loop until all tasks are blocked in python

Run event loop until all tasks are blocked in python Question: I am writing code that has some long-running coroutines that interact with each other. These coroutines can be blocked on await until something external happens. I want to be able to drive these coroutines in a unittest. The regular way of doing await on …

Total answers: 5

Why does using list(dict_keys()) here, return an empty list?

Why does using list(dict_keys()) here, return an empty list? Question: I am trying to make a Class to represent a Library with a nested class to represent the individual books. class Library: class Book: book_data = {} def __init__(self, title, year, isbn, author): self.title = title self.year = year self.isbn = isbn self.author = author …

Total answers: 1

Python Module not found ONLY when .py file is on desktop

Python Module not found ONLY when .py file is on desktop Question: Only for a .py file that is saved on my Desktop, importing some modules (like pandas) fail due to Module not found from an import that happens within the module. This behaviour doesn’t happen when the file is saved to a different location. …

Total answers: 2

Efficient and fast way to search through dict of dicts

Efficient and fast way to search through dict of dicts Question: So I have a dict of working jobs each holding a dict { "hacker": {"crime": "high"}, "mugger": {"crime": "high", "morals": "low"}, "office drone": {"work_drive": "high", "tolerance": "high"}, "farmer": {"work_drive": "high"}, } And I have roughly about 21000 more unique jobs to handle How would …

Total answers: 2

PyCharm [Intellij] auto-import from Binary Skeletons instead of standard python library

PyCharm [Intellij] auto-import from Binary Skeletons instead of standard python library Question: I’m trying to import Decimal from decimal but when I try and do this using Intellij it just says I can import from _decimal instead which is in the Binary Skeletons. I’m using Poetry and Python 3.10, and it’s almost certainly something wrong …

Total answers: 2

match case in micropython – SyntaxError: invalid syntax

match case in micropython – SyntaxError: invalid syntax Question: I am using python 3.10.5 on my raspberry pi pico and I am trying to use match & case instead of if statements When I try to run the program it returns an error: Traceback (most recent call last): File "<stdin>", line 22 SyntaxError: invalid syntax …

Total answers: 1

How to migrate `shelve` file from Python 3.10 to Python 3.11

How to migrate `shelve` file from Python 3.10 to Python 3.11 Question: Code: with shelve.open("cache") as db: … Python 3.10.9 result A cache.db file is created. Python 3.11.1 result Three files are created: cache.cir, cache.bak, cache.dat. What I need I have important data in the old file and I need to keep using that data …

Total answers: 2

create dataclass with optional attribute

create dataclass with optional attribute Question: I’m trying create dataclass with optional attribute is_complete: from dataclasses import dataclass from typing import Optional @dataclass(frozen=True) class MyHistoricCandle: open: float high: float low: float close: float volume: int time: datetime is_complete: Optional[bool] But when i init MyHistoricCandle object without is_complete attribute: MyHistoricCandle(open=1, high=1, low=1, close=1, volume=1, time=datetime.now()) Getting …

Total answers: 1