Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
[R] Bert and XLNet: 85% Neurons Redundant, 92% Removable for Downstream Tasks
https://aclanthology.org/2020.emnlp-main.398.pdf

/r/MachineLearning
https://redd.it/12ms3wo
New search package in python

Searchlix

My first python package on PyPI

I want to try how I can develop a python package and upload it, and the result was: Searchlix

It is a simple and powerful package which helps with searching for patterns, emails, phone numbers and words in texts and websites! (Web scraping)

Some of the features:
-Patterns search in text (KMP algorithm)
-Word search in text
-Search for page name in website
-Find emails in text / Email validation
-Find emails in a website page
-Find a phone number in text / Phone number validation
-Find a phone number in a website page

And I will provide further features and examples in the future

I would be thankful if any one who tried it could show us how he used it (case study) and if there are any further suggestions

https://pypi.org/project/searchlix/

/r/Python
https://redd.it/12mw0dc
Mastering SOLID Principles in Python: A Guide to Scalable Code

The Single Responsibility Principle (SRP) is a fundamental SOLID principle that states that a class should have only one reason to change.

/r/Python
https://redd.it/12mxuoi
Basic question on what this syntax comes from: is this python code I am not familiar with; is it django -- Just not sure what to even call it so i can look up info on it.

/r/django
https://redd.it/12n1r76
Is having a single app standard in Django realm ?

hi there,

i started this new job as a Django backend developer. we have around 20 models. what i want to do is split them into couple apps along with their respective views etc. but my team mate argued that what i do is not right and all Django projects use a single app to manage everything.

is this correct ? what is the right way of doing this. a single app with 20 models in a models.py file seems hard to read/reach for me.

should i create separate apps or should i create multiple folders in a single app.

how do you structure your projects ?

/r/django
https://redd.it/12mwx7e
Django + Nextjs overkill?

I have built Django websites in the past as well as DRF + React. I know that the cool kids nowadays use Nextjs. It does indeed have a lot of good stuff but I feel kindda lost whether is a nice idea to combine the two frameworks and just use Nextjs as the frontend. I have read some posts mentioning that you will find a lot of problems down the road (CORS related, etc).

The reason to stick with DRF as backend is that I'm way more better developer and more used to python while I just know a couple of things in the Javascript world.


Any experience stories, guidance would be much appreaciated.

/r/django
https://redd.it/12neaj8
Sunday Daily Thread: What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.

/r/Python
https://redd.it/12nnqs3
Pip 23.1 Released - Massive improvement to backtracking

Pip 23.1 was just released a few hours ago. You can check the release announcements here and the change log here.

I would like to highlight the significant improvement in backtracking that is part of the requirement resolver process in Pip. This process involves Pip finding a set of packages that meet your requirements and whose requirements themselves don't conflict.

For example, let's say you require packages A and B. First, the latest versions of A and B are downloaded and Pip checks their requirements, let's say Pip finds that A depends on C==2 and B depends on C==1. These two latest versions of A and B are not compatible, so Pip will try to find an older version of A and/or B where they have compatible dependencies. C in this case is called a transitive dependency because it's a dependency of a dependency.

Prior to Pip 20.3, the default process for Pip would allow conflicting requirements to install if they were transitive dependencies where the last one specified would be the one installed. This was not satisfactory for a lot of projects that had larger set of requirements because it meant package versions that did not work together could be installed

/r/Python
https://redd.it/12n5lai
problem with psycopg

so i am working on some django from a book and trying to do a project. it was working good but when i had to use docker-compose down and docker-compose up -build -d command again so changes would commit now it has some errors.

​

it says psycopg is not intalled but it was working good and i made sure it is installed so i dont understand what can be the problem here. maybe the error is about database, which i changed in the settings but why id this error occuring now?

here is my database settings

https://preview.redd.it/wc365183hvta1.png?width=680&format=png&auto=webp&v=enabled&s=a3d83cc453f13da03d3e452f7da9696f5e587e21

maybe someone had a similar experience and can help me, i would appreciate.

by the way when i run docker-compose up -d --build command it gives me this error

​

https://preview.redd.it/39lvncvthvta1.png?width=1219&format=png&auto=webp&v=enabled&s=74807ec07c2ea82a5a238293a4f10a840c127568

​

thanks for helping

/r/djangolearning
https://redd.it/12m1vq8
Flask changing src and PATHS

I've used Flask(__name__, template_folder="mijn_project/templates") for some reason all my PATHS don't work. app.py is stored in / and my project is stored in /mijn_project/. none of my templates can find the images location or bootstrap, css, js etc. but when I run my HTML template it show the CSS, images, lib without errors. what's going wrong? PS. the structure is not my idea, my teacher demands this. and I tried every PATH ../static, /static/, ../../static but nothing works. and its a local test

/r/flask
https://redd.it/12n3w4m
How do I get current values from the database in a dropdown form

Hi,

TL:DR: I want to pass the values of a database model into the options in a dropdown menu.

I am building a application with different card types. Each card type has a different color. To keep track of the users preferences I created a database model where for each user I keep track of their color (and also Icon and label).

Basically the user can say:- legend_1 is yellow, I call it "ambition" and I want a thumb up icon.- Legend_2 is blue etc etc

here is the model:

models.py

# Create your models here.
class CardPreferences(models.Model):
<!--Some other stuff not related to question -->
legendlabel1 = models.CharField(blank=False, maxlength=40, default='legend1')
legendhexcolor1 = models.CharField(blank=False, maxlength=6, default='78E7BF')
legendicon1 = models.CharField(blank=False, maxlength=40, default='thumbs-up-solid.svg')
legend
label2 = models.CharField(blank=False, maxlength=40, default='legend2')
legend
hexcolor2 = models.CharField(blank=False, maxlength=6, default='51c1ff')
legend
icon2 = models.CharField(blank=False, maxlength=40, default='thumbs-up-solid.svg')


/r/djangolearning
https://redd.it/12o8jow
Database on Local Machine - Still Pulling Heroku Postgres Database

Recently my main computer rig died and I moved onto a new computer.

I am trying to get my local development mode back up and running but am running into trouble, amateur programmer at best, doing this as a fun hobby.

Anyways, in the process of trying to get the website back up and running, I forgot to set my local environment variable of "DEVELOPMENT_MODE" to "True" and ran "python manage.py collectstatic" and "python manage.py runserver" and my local machine points to the postgres database that I have on with Heroku.

I thought this should be a pretty easy fix and change "DEVELOPMENT_MODE" to "True", but the local database is still referencing the postgres database. Any ideas on how to get django to point the the local sqlite3 database?

Code in reference, settings.py:

if DEVELOPMENTMODE is True:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE
DIR, "db.sqlite3"),


/r/djangolearning
https://redd.it/12kb0gg
Flask Sessions not working with blueprints

I am using flask sessions, i recently changed my code structure to be blueprint based, it has broken sessions. Whevenver i try to access sessions inside a blueprint, it is giving me
RuntimeError: The session is unavailable because no secret key was set.  Set the secret_key on the application to something unique and secret.


This is the code from the main application:
app = Flask(__name__)
app.register_blueprint(authModule, url_prefix='/auth', cookie_path='/')
app.secret_key = environ.get('secret_key')
app.config['SESSION_COOKIE_PATH'] = '/'


Can anybody tell me what is causing this?

/r/flask
https://redd.it/12oexr1
I want to display a stock market ticker on a HTML page.

Here's the Github link to my code : https://github.com/SachinPrab/microinvestment/blob/81d2e32fcd48d58704ad2668d05164d2f2ad33c0/app.py

I want to display the output of the above code in this HTML page (Github link) : https://github.com/SachinPrab/microinvestment/blob/81d2e32fcd48d58704ad2668d05164d2f2ad33c0/ticker.html

The above page should be opened when the user clicks on the button at the bottom of this page: https://github.com/SachinPrab/microinvestment/blob/81d2e32fcd48d58704ad2668d05164d2f2ad33c0/stocks.html

Can someone please point out the error in the Flask application that I have created? I am able to view only the heading which reads "Stock Market Ticker" upon running the code in PyCharm editor but I'm not able to view the ticker. Thanks in advance.

/r/flask
https://redd.it/12kqncf
Announcing Polyfactory - a powerful mock data generator for dataclasses, Pydantic and more

Hello r/Python!

Today I'd like to formally announce the first stable release of Polyfactory \- a powerful mock data generator built around type hints and support for some of the most popular data modelling solutions such as Pydantic models, dataclasses, typed-dicts and more!

## Once upon a time there was pydantic-factories

Some of you may already know this project as "pydantic-factories"; A name under which it garnered a decent amount of popularity since it's inception. Pydantic-factories and Polyfactory have a lot in common. In fact, Polyfactory is pydantic-factories 2.0. That's why we also decided to continue the version number and release the first version of Polyfactory as 2.0.0.

But why the name change?

A main motivator for the 2.0 release was that we wanted to support more than just Pydantic models, something which also required a change to the pydantic-fatories' core architecture. As this library would no longer be directly tied to Pydantic, polyfactory was chosen as a new name to reflect its capabilities; It can generate mock data for dataclasses, typed-dicts, Pydantic, odmantic, and beanie ODM models out of the box.

Polyfactory is all that pydantic-factories was and more!

## So what can it do?

Let's look at a very basic example using dataclasses:



/r/Python
https://redd.it/12o69ld