135201
You will be muted until you read the rules. Read them! @Rules_for_Python A group about the Python programming language. Offtopic things go here: @pythonofftopic Resources to learn python: @pythonres Group for Hy: @hylang Selenium: @SeleniumPython
I have made FastAPI style DI for flask if you want to use it: https://github.com/razorblade23/di-flask
Otherwise, you can use g to keep the session "opened" but i would advise against that as session should be closed on every transaction.
Its better to open session on each transaction and close it afterwards, prefferebly using with Session(engine) as session: context manager
Also me and other people, but this is the wrong group to talk about that
Читать полностью…
A different group where you can talk about what you do and ask about how other people feel without being told that your contributions aren't suited for the group.
Читать полностью…
Create a telegram bot that answers with a beginner project everytime someone asks for beginner projects
Читать полностью…
pydroid3 is being updated every time with the latest libraries and modules
Читать полностью…
I almost found this after 2 year old chat, i also want to found a best choice, so i want to know what do you use or choose to use till now, as now i am a beginner.?
Читать полностью…
struct _longobject {
// _object head
uint64_t ob_refcnt_full; // 8 bytes
PyTypeObject *ob_type; // 8 bytes
// _PyLongValue long_value
uintptr_t lv_tag; // 8 bytes
digit ob_digit[1]; // 4 bytes
};PyLongObject on platforms where sizeof(void *) > 4 and sys.int_info.bits_per_digit == 30 was defined as a struct with trailing array, each digit is an uint32_t
Читать полностью…
Python Brain Teaser (Expert Level)
Can you guess the exact console output of this Python 3.11+ code? It tests deep internals like memory management, constant folding, and mutating "immutable" objects.
import sys
import ctypes
def modify_internals():
a = (1, 2)
b = (1, 2)
c = 1000
d = 1000
# 1. What do these print?
print(a is b)
print(c is d)
# 2. Bypassing safety checks to mutate an integer in-place
# (Overwriting the memory of 'c' with the data from '1001')
offset = sys.getsizeof(0)
ctypes.memmove(id(c) + offset, id(1001) + offset, 8)
# 3. What does this print now?
print(d)
modify_internals()
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate):
with Session(engine) as session:
db_hero = Hero.model_validate(hero)
session.add(db_hero)
session.commit()
session.refresh(db_hero)
return db_hero
db_hero, which is a Hero model instance. However, because response_model=HeroPublic is specified in the FastAPI decorator, FastAPI automatically validates/converts the returned object according to the HeroPublic response model.response_model that I can specify in a Flask route decorator, so that my function can simply return a Hero object and Flask automatically serializes/validates it according to a HeroPublic schema?return HeroPublic.model_validate(hero_obj)
I was trying to use SqlModel , Pydantic in a flask web app, the problem i am finding, like my confusion is i found some code examples like they are using flask.g, actually i am confused should i will use this in my real code to generate session for the sqlmodel, as in flask there is not any Depends like fastapi has one,
i am confused how i should start using the session when i will follow the sqlmodel functions for login, register or some others things,
my main problem is shoudl i start using this, i dont know will this ok in real production,
def get_db_session() -> Session:Читать полностью…
if "db_session" not in g:
g.db_session = Session(engine)
return g.db_session
Read it
pererikbergman/repository-design-pattern-e28c0f3e4a30" rel="nofollow">https://medium.com/@pererikbergman/repository-design-pattern-e28c0f3e4a30
Apply to your project
Does not matter if its Django, Flask, or whatever else you may choose
Design patterns are language (and framework) agnostic
hello everyone
who can help me with repository pattern in django ?
is docker like application can i run of python webapp like hosting?
Читать полностью…
Does anyone have the latest version of Python for Android?
Читать полностью…
I am trying to use Flask + Sqlmodel with DDD structer, but i am very beginner in this case
Suppose i am making a database functions in a class Repository which will have some methods like, add_user, remove_user, update_user_data, like this...
But then see below code i got from some places and it say if i will use this i will not need to use the
with session(engine) as session:
session.add(...)
session.update()
def get_session():
with Session(engine) as session:
yield session
why would u even care about Undefined behavior questions
Читать полностью…
Yes, but I don't know anyone on GitHub who publishes them
Читать полностью…
In other words, do you have channels that share bot files or Python tools?
Читать полностью…