python | Unsorted

Telegram-канал python - Python

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

Subscribe to a channel

Python

I have a basic Flask example repo that I copied to a VPS. In the repo, my Python main.py code looks like this:

if __name__ == "__main__":
app = create_app()
app.run(
host=settings.app.host,
port=settings.app.port,
debug=settings.app.debug,
)


On the VPS terminal, I navigate to my directory and run:
uv run main.py

As a result, the app starts running on a port (e.g., 9999), and I can access the website from other devices via ip_addr:9999.

However, even though the VPS provider's dashboard shows my system has been running for over 10 hours, the app stops working after a short time (10 minutes, 1 hour, etc.). I noticed that other processes are still running, but this specific port closes automatically. I then have to go back to the VPS and run main.py again.

Is this expected behavior in reality? How can I keep my Python app running on this same port without it stopping? or i am missing something here 🐍🚀

Читать полностью…

Python

By the way, my English is not good, so I use Google Translate, which may have problems with phrasing and such.

Читать полностью…

Python

I think he is copy pasting answers from Ai. but I'm not sure

Читать полностью…

Python

yeah, telegram go brr.
also, there's the case for yield and map() here, but feels out of scope lol

Читать полностью…

Python

what a shitty fix ngl

Читать полностью…

Python

The Answer:
The correct output is **B: [4, 4, 4, 4, 4]*Why? (The "Late Binding" Trap)p)**
In Python, closures look up the variable name in the outer scwhen the function is calleded**, not when it’s defined. By the time you call the functions in the list, the loop has already finished, and the variable i is left at its final value: 4. All your function objects are referencing the same i.

**The Professional Fix:**
To capture the value at the time of definition, you need to "freeze" it. The standard way to do this is by default argumentgument**:

def create_multipliers():
multipliers = []
for i in range(5):
# By setting i=i, we capture the current value
# of i as a local variable for this function instance.
def multiplier(x, i=i):
return x * i
multipliers.append(multiplier)
return multipliers

Now, each function maintains its own snapshot of i, and the output will be the expected [0, 1, 2, 3, 4].

*This is a classic "gotcha" in Python. Understanding scope is what separates a beginner from a production-ready engineer.*

Читать полностью…

Python

pls help me to get the python]

Читать полностью…

Python

Python Quiz: The "Late Binding" Trap 🐍

Let’s test your understanding of Python closures and scoping. What is the output of the following code snippet?

def create_multipliers():
multipliers = []
for i in range(5):
def multiplier(x):
return x * i
multipliers.append(multiplier)
return multipliers

funcs = create_multipliers()
print([f(1) for f in funcs])

Options:
A) [0, 1, 2, 3, 4]
B) [4, 4, 4, 4, 4]
C) [0, 0, 0, 0, 0]

Читать полностью…

Python

Check out @PythonRes, a channel for Python resources - video courses, pdf books, tutorials and other info to help you learn Python.

Читать полностью…

Python

how do you jump from python basics to cyber security?

Читать полностью…

Python

this is a python chat, not a cyber security chat, go to @pythonofftopic

Читать полностью…

Python

This is an off topic question, go to @pythonofftopic

Читать полностью…

Python

Can I get a Sugesssion:-

Why they say to use @dataclass, even i think to use pydantic 's BaseModel to represent data in my domain entities, even i will use pydantic all over my repo as a must need library for working with class easily.

Читать полностью…

Python

Hello i am getting frastrutated to use Alembic today newly in a new repo:
1st:-> alembic init --template pyproject alembic
after i run this command it generate a alembic/env.py in the file i edited this:

from sqlmodel import SQLModel
from models import *
# upper import all the model class i have

config.set_main_option(
name="sqlalchemy.url",
value=DATABASE_URL,
)
target_metadata = SQLModel.metadata

After i adding these thigns in the alembic/env.py, i found the issue:
alembic revision --autogenerate -m "initial migration"
Running this cause error:
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [alembic.util.messaging] Can't locate revision identified by 'f29236eae9ff'
FAILED: Can't locate revision identified by 'f29236eae9ff'

is this any mistake i am doing in my way any logic problem or maybe as i copy past code of alembic1.19.2 and now today 1.20.0 is causing the issue:
What is the best way i can check how i can solve this.

i did vs code's ctrl+shift+f search but not foudn anythign pointing f29236eae9ff.

Читать полностью…

Python

At least you have fun.

Читать полностью…

Python

This group is to help you on specific issues you have on YOUR code, so you have to show the code you wrote and explain where and why you are stuck... as simple as that

Читать полностью…

Python

Yes, I will try to post spring content from now on. But I don't think it matters where we copy and paste from, as long as we learn something. This post was like this, otherwise I will try to find the best programming tips and skills and post them here.

Читать полностью…

Python

Your copy and paste doesn't look so good.

Читать полностью…

Python

depending on context i would go with either of these, default argument binding just seems like a confusing hack to me tbh

import functools

def multiplier(x, i):
return x*y

def create_multipliers():
return [functools.partial(multiplier, i=i) for i in range(5)]

or
def create_multipliers():
def make_multiplier(i):
def multiplier(x):
return x * i
return multiplier
return [make_multiplier(i) for i in range(5)]


intent is far more obvious with these

Читать полностью…

Python

❗️ Message from ‎Jafar Salimi [532744334] was reported to the admins.​​​​​​​​​​​​​​​

Читать полностью…

Python

cuz it's capturing i by reference, not by value

Читать полностью…

Python

I am the beginner and I want to learn python

Читать полностью…

Python

If u seriously wanna learn Python, my 2 cent is to go this path:
1- Read Python Crash Course book && Do ALL the practices & coding there (mocking, changing some segments, re-doing the practices on ur own)
2- Read Effective Python (125 specific ways ...) not the old version (90 specific ways ...) & apply ur learning about best practices onto what u've done in Python Crash Course.

Avoid getting lost in thousands of articles out there.

Once u learn everything in those 2 books, u're way better than lots of Python devs in writing correct & idiomatic Python.

But if u're not genuinely interested & just wanna look cool, we're in post-llm era. Easy to look like magicians by a couple of prompts. So, don't waste ur time.

Читать полностью…

Python

Can I get a beginner guide on python

Читать полностью…

Python

Oh I wanted to know the basics in python rather

Читать полностью…

Python

Hello can anyone help me on cyber security
Am a beginner

Читать полностью…

Python

Hello, can I find an online job opportunity?

Читать полностью…

Python

Thanks All.
I got solved, actually i didnot add the
import sqlmodel
in my script.py.mako thats why it cause the problem till now 😅

Читать полностью…

Python

wait , is that you cookie ?

Читать полностью…

Python

how can you still send normal messages.?

Читать полностью…
Subscribe to a channel