Telegram Group Search
Reactive programming for Python with live-cells-py

live-cells-py (Live Cells Python) is a reactive programming library which I ported from [Live Cells](https://livecells.viditrack.com/) for Dart.

# What my project Does:

You can declare *cells* which are observable containers for data:

import live_cells as lc

a = lc.mutable(0)

Cells can be defined as a function of other cells:

a = lc.mutable(0)
b = lc.mutable(1)

c = lc.computed(lambda: a() + b())

`c` is defined as the sum of the values of cells `a` and `b`. The value of `c` is automatically recomputed when the value of either `a` or `b` changes.

The definition of `c` can be simplified to the following:

c = a + b

Which reads like an ordinary variable definition

You can define a *watch* function which runs whenever the value of a cell changes:

lc.watch(lambda: print(f'The sum is {c()}'))

This watch function, which prints the value of `c` to standard output, is run automatically whenever the value of `c` changes.

More complex computed cells and watch functions can be defined using decorators:

n = lc.mutable(5)

@lc.computed


/r/Python
https://redd.it/1cwcm7f
Dive into DevOps ebook Humble Bundle supporting the Python Software Foundation

https://www.humblebundle.com/books/dive-into-dev-ops-no-starch-books

Be sure to click on "Adjust Donation" and "Custom Amount" and then max out the amount going to the Python Software Foundation. (From $1.75 to $24.50!)

For $30 you get the following ebooks from No Starch Press:

978-1718501928 2021 Automate the Boring Stuff with Python, 2nd Edition
978-1593275891 2014 DevOps for the Desperate
978-1593278632 2018 How Linux Works, 3rd Edition
978-1593271411 2007 The Book of Kubernetes
978-1593274764 2013 PowerShell for Sysadmins
978-1593278922 2018 Practical Vulnerability Management
978-1593272036 2010 Practical SQL, 2nd Edition
978-1593275099 2013 Practical Linux Forensics
978-1718500884 2021 Eloquent JavaScript, 3rd Edition
978-1718503007 2023 Cybersecurity for Small Networks
978-1593279943 2020 The Linux Command Line, 2nd Edition
978-1593279523 2019 Web Security for Developers
978-1718501485

/r/Python
https://redd.it/1cwqkx7
Using an existing PostgresDB in a new Django project

I used inspectdb to auto generate models, and four fields were skipped without warning, there's something like 20 fields so it was hard to immediately detect, and fortunately during testing I did find that there were missing fields. My question is how have you gone about moving over an existing db into django -- consider for example if I have dozens of tables to move over and want some sort of guarantee or alerting when fields are omitted. Is there something more robust than inspectdb? Or, what is your process for reviewing a large set of generated models from inspectdb that minimizes human error? My approach thus far was to print out column names, print out db metadata, and cross compare -- is this the best?

/r/django
https://redd.it/1cwni82
Tuesday Daily Thread: Advanced questions

# Weekly Wednesday Thread: Advanced Questions 🐍

Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.

## How it Works:

1. **Ask Away**: Post your advanced Python questions here.
2. **Expert Insights**: Get answers from experienced developers.
3. **Resource Pool**: Share or discover tutorials, articles, and tips.

## Guidelines:

* This thread is for **advanced questions only**. Beginner questions are welcome in our [Daily Beginner Thread](#daily-beginner-thread-link) every Thursday.
* Questions that are not advanced may be removed and redirected to the appropriate thread.

## Recommended Resources:

* If you don't receive a response, consider exploring r/LearnPython or join the [Python Discord Server](https://discord.gg/python) for quicker assistance.

## Example Questions:

1. **How can you implement a custom memory allocator in Python?**
2. **What are the best practices for optimizing Cython code for heavy numerical computations?**
3. **How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?**
4. **Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?**
5. **How would you go about implementing a distributed task queue using Celery and RabbitMQ?**
6. **What are some advanced use-cases for Python's decorators?**
7. **How can you achieve real-time data streaming in Python with WebSockets?**
8. **What are the

/r/Python
https://redd.it/1cwuc7k
Dash Pip Components

Hey everyone, just released 8 new pip components for plotly and dash including:

`Full Calendar Component` - A Full Calendar Component for Dash
Dash Summernote - A rich text WYSIWYG Editor for Dash
`Dash Emoji Mart` - A Slack-like Emoji Picker for Dash
Dash Charty - A Charting Library for Dash
`Dash Image Gallery` - A Image Gallery Component for Dash
Dash Swiper - A Swiper Component for Dash
`Dash Insta Stories` - An Instagram Stories Component for Dash
Dash Credit Cards - A Credit Card Component for Dash

Documentation can be found here:

https://pip-install-python. com/

The repo for the github can be found here:

https://github.com/pip-install-python/pip-docs


/r/flask
https://redd.it/1cwp5x7
try... except... finally!

Haven't seen this syntax used very often and was wondering why. During error handling, if you have something to run independent of the success, you can use finally.

from your_library import DataProcess

engine = DataProcess()

try:
engine.io()
engine.process()
engine.some_more_io()
except Exception as e:
engine.revert()
raise e
finally:
engine.cleanup()


# VS

from your_library import DataProcess

engine = DataProcess()

try:
engine.io()
engine.process()
engine.some_more_io()
except Exception as e:
engine.revert()
engine.cleanup()
raise e
engine.cleanup()


# VS


from your_library import DataProcess
from contextlib import contextmanager


@contextmanager
def process_data(engine: DataProcess):
try:
engine.io()
yield engine
except Exception as e:
engine.revert()
raise e
finally:
engine.cleanup()


with process_data(DataProcess()) as engine:
engine.process()
engine.some_more_io()


/r/Python
https://redd.it/1cx0dh4
A Beginner's Guide to Unit Testing with Pytest

Hey r/python!

I wrote a guide on how to use Pytest, covering a bunch of important features like designing tests, filtering tests, parameterizing tests, fixtures, and more. Check it out on this link.

/r/Python
https://redd.it/1cwm734
Storing discount info in purchase item as a JSON field or using a separate model?

During the pass few days I've been debating how to best store the discount information in my purchase items.

We allow the users of our marketplace to modify the "Discount" model, for example if they want to change the amount of discount for the same code over time, etc.

Because of this we want to store the actual values that the discount code had at the time of the purchase.

**Option A:** Using a JSON field. In this case we can just create a dictionary with the most important info and store it inside a single field.

class PurchaseItem(models.Model):
...
discount = models.JSONField(null=True, blank=True)

And the discount dictionary would look like this:

{"id": 5, "code": "HELLO10", "type": "vendor", "amount": "32.00", "value": "28.80", "is_fixed": false}

**Option B:** Second option is to create a separate model to store this information, instead of JSON.

class PurchaseItem(models.Model):
...
discount = models.ForeignKey(DiscountApplied, null=True)


class DiscountApplied(BaseModel):


/r/django
https://redd.it/1cx1cmc
How to demo django project if Github pages can't?

I am a real beginner at code and I've recently been trying to learn new things, django being one of them. How would I showcase my project on future resumes or people if I cannot deploy it on Github pages and I am not willing to pay?

It's probably a stupid question, but do employers have the time to just look at the github repo and run the server

/r/django
https://redd.it/1cwupa9
How to relate the keys extracted from the API into app.py and index.html

The output on the terminal as part of print statement shows:

{'ticker': 'MARA', 'price': '22.32', 'change\_amount': '2.87', 'change\_percentage': '14.7558%', 'volume': '65114509'}

So ticker, price, change\_amount, change\_percentage are keys.

Now, this is the current app.py:

from flask import Flask, render_template, request
import requests
from sqlalchemy import create_engine, Column, Integer, String, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# Configure Flask app
app = Flask(__name__)

# Configure database connection details (replace with your credentials)
SQLALCHEMY_DATABASE_URI = 'sqlite:///mydatabase.db'
engine = create_engine(SQLALCHEMY_DATABASE_URI)
Base = declarative_base()

# Define database model for storing stock data (optional)
class StockPrice(Base):
    __tablename__ = "stock_prices"

    id = Column(Integer, primary_key=True)
    symbol = Column(String(10), nullable=False)
    price = Column(Float, nullable=False)

    def __repr__(self):
        return

/r/flask
https://redd.it/1cx4vqo
African Developer small rant

A little rant.
I am 27F. Does anyone really talk about how frustrating it is to be a jobseeker in Africa? I graduated in 2019 with an Accounting bachelor’s degree. I couldn’t find any decent-paying job, so I ended up working as a commercial property caretaker making around $260 per month. Sounds like nothing and yes it wasn’t much but I was able to find a single room and rent and also buy basic foodstuff. Buying an extra banana meant I was squeezing my budget. I tried content creation, doing online writing gigs to supplement my income and luckily, I got by.

Forward to November 2021, I moved in with my then-bf, thankfully, he has been nothing but supportive, and I didn’t have to pay rent so I could save a little bit from my earnings.

I went back to school to finish up my professional papers (CPA in my country has different exams from your accounting degree.) Supposedly, the professional papers should give you an edge but that wasn’t my case.

Fast forward to October 2022, I changed course. I had been running a WordPress site for like six years at this point, just writing random University experiences so I knew anything

/r/django
https://redd.it/1cx3jc9
Durable Python - Infrastructure failures should not stop the process

Durable Python enables developers to write Python code while an underlying system ensures reliability and resilience.

It automatically handles state persistence, fault tolerance, and retry mechanisms, allowing developers to focus on business logic without worrying about infrastructure concerns.

Consider the following code, in case the process terminates in the middle of execution, in case the process is killed or due to hardware failure, the process will not complete.


import requests
import time


SLEEP_SECONDS = 3
URL = "http://localhost:9980/webtools/api/msgs"

def on_http_get(data):
for i in range(10):
print("Loop iteration: %d of 10" % (i + 1))

# Send a POST request to the application
requests.post(URL, data = "This is my " + str(i) + " iteration...")
time.sleep(SLEEP_SECONDS)


But actually, I would like the process to survive restarts and continue from the spot it terminated, especially if it's a long running process. For this we need Durable Python.

I was wondering which use cases can take advantage of this technology.


/r/Python
https://redd.it/1cxbyf6
Example integrations of python packages that can be used in Python notebooks [matplotlib, seaborn, plotly, altair-viz]
https://runmercury.com/use/

/r/IPython
https://redd.it/1cx9034
Test my site?

www.chatgod.co.uk

Everything is almost complete. I just need to finish the accounts page and that is it! :)

Can someone poke around and try to see if you can find any bugs, or likewise whether your experience was good and nothing wrong.

Thank you!

/r/flask
https://redd.it/1cxdddr
Discussion + Live Chat app

Made a lil discussion board mixed with live chat web app (using a free domain for now).

(Its mostly filled with exemplar data atm)

Feel free to take a look, lmk what you think, whats good, whats bad...

Tangents (tanagent.pythonanywhere.com)

/r/flask
https://redd.it/1cxjcs5
Selling Social Networking App

Hey guys, so heres my story, around a year ago (September) I created a social networking app for my advanced software project class, and it turned out extremely well, and I have been maintaining the app and continuing to consistently update and fix the app as well. I feel confident in my app that people will use it and thoroughly enjoy it as well. I would like to sell the app or at least make some sort of income from it, as I put too much time and effort into making it. Please let me know any ideas or recommendations you might have. Thank you all!

/r/flask
https://redd.it/1cwqejp
Wednesday Daily Thread: Beginner questions

# Weekly Thread: Beginner Questions 🐍

Welcome to our Beginner Questions thread! Whether you're new to Python or just looking to clarify some basics, this is the thread for you.

## How it Works:

1. Ask Anything: Feel free to ask any Python-related question. There are no bad questions here!
2. Community Support: Get answers and advice from the community.
3. Resource Sharing: Discover tutorials, articles, and beginner-friendly resources.

## Guidelines:

This thread is specifically for beginner questions. For more advanced queries, check out our [Advanced Questions Thread](#advanced-questions-thread-link).

## Recommended Resources:

If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.

## Example Questions:

1. What is the difference between a list and a tuple?
2. How do I read a CSV file in Python?
3. What are Python decorators and how do I use them?
4. How do I install a Python package using pip?
5. What is a virtual environment and why should I use one?

Let's help each other learn Python! 🌟

/r/Python
https://redd.it/1cxmpeo
I made a Traversible Tree in Python

Comparison
It is inspired from the existing tree command on linux and windows too So basically it is just like the tree command, it shows you a tree of the current directory structure.

What My Project Does
It basically gives you a birds eye view of your dir structure and quickly navigate to the folder you want to without having to know its path or doing cd ../../.. many times.

There are a bunch of command line args such as setting the paths, flags to show dot directories, set head height (no. of parent dirs shown) and tail height (depth).

You can traverse around the tree using various key presses (inspired from vim keybindings) and based on the given argument (-o, -c or --copy) you can output the value (the node to which you traversed), cd into it and have it copied into your clipboard.J

I had created this for my assignment and had a lot of fun with it. Tried to implement as much clean code and good design as I could but its still a mess and active work in progress tbh (added unit tests lol). And the rendering is still a little slow.

Do check it out: pranavpa8788/trav: A Traversible

/r/Python
[https://redd.it/1cxfaph
D Simple Questions Thread

Please post your questions here instead of creating a new thread. Encourage others who create new posts for questions to post here instead!

Thread will stay alive until next one so keep posting after the date in the title.

Thanks to everyone for answering questions in the previous thread!

/r/MachineLearning
https://redd.it/1cvq77y
Programmable Semantics (Eval, Semicolon, Assignment) for Python

I've seen programmable semantics (eval-hacking, macros) in LISPs and in Haskell-likes(Monads/Template Haskell), the overall techinque in OOP languages is called "Aspect Oriented Programming". Has this kind of thing been discussed before, and is it Pythonic it could allow a lot of Python code to be shorter. Python has sys.set_trace that sort of allows some form of programmable semantics but its mostly for debugging.

Programmable assignment(variables) are like setters/getters/properties, but instead of being run on o.x = 5, you could run them on "all local assignments" isnside a context manager or in a decorated function. On every assignment you could do stuff like log the values, update dependencies, notify objects, do a database transaction, do persistance, calculate other values, without having to explicitly do so for every assignment statement.

Programmable semicolons (such as Haskell Monads, or reprogramming Lisp do/progn/let) could allow you to have the same code run either synchronous, async, get undo/history support, break on error, rollback, logging in between lines, changing local/global variables in between each line, database access in between lines, checking values for errors, ignoring certain statements, etc... You can think of a semicolon like an "unrolled for loop"/iterator ran for each code line.

/r/Python
https://redd.it/1cxp7qe
2024/05/22 08:06:07
Back to Top
HTML Embed Code: