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
AMA: Ask me how I built amigoingonholiday.co.uk - Friday 20th Jan. at 18:00 GMT

Hi everyone,

I'm Dom (aka: u/SecondaryPath), the author of https://amigoingonholiday.co.uk. I'm hosting an AMA with members of the r/Flask community this Friday (20th Jan. 2023) at 18:00 GMT.

Feel free to ask me questions on how I built this Flask application, as well as anything else Flask/Python/Web Dev related!

YouTube live link: https://www.youtube.com/watch?v=4eCHYvcbAhg

/r/flask
https://redd.it/10fe89u
how can I redirect to another page from an html template in flask

I have a template where I have a back button as follows:

<div class="ui basic segment center aligned">

<i class="link arrow circle left big icon" onclick="handleBackButton()"></i>

</div>

At the moment, this handler just calls some dummy JS method but what I would like to do is redirect to the `index` page on flask. I know from the python code, I can call something like:

render_template("index.html")

or

redirect(url_for("index"))

I wonder if I can do the same from the HTML side of things. I could find many examples of doing this from the python side but nothing from the template side.

/r/flask
https://redd.it/10fejrp
I'm creating an app based on Flask, Zappa, Plotly/Dash and AWS Lambda. Do you have any examples/templates/python codes of apps built on Flask? The idea is create a simple one-page website with a sign up/sign in section and an app based on a csv file stored in s3 (It will be displayed through Dash).



/r/flask
https://redd.it/10f4g33
Flask-sqlalchemy

Is it better to have quite a lot of small tables in a database or fewer, much larger, tables?

I am currently making an app that is data intensive and I can’t decide whether to split out tables as much as possible to make it simple or to keep the data together in 1 table.

I think smaller tables would be better as it won’t take as long to query them (not that I’ll have millions of rows, so that probably isn’t a factor).

Please let me know what you think.

P.s. I’m currently using sqlite3 if that’s relevant

/r/flask
https://redd.it/10bt9n8
Help with a good Jinja Extension?

I'm just starting to learn Flask and working in VSCode. I tried using better Jinja, but when it only works when I set the language mode to Jinja-HTML. But when I do that, VSCode treats HTML as just plain text, and the language mode is HTML it treats Jinja as just plain text. Is there a way for it to handle properly handle both at the same time? The videos I'm watching seems to do exactly what I'm looking for, but of course the instructor makes no mention of it.

/r/flask
https://redd.it/10bvy4u
Thursday Daily Thread: Python Careers, Courses, and Furthering Education!

Discussion of using Python in a professional environment, getting jobs in Python as well as ask questions about courses to further your python education!

This thread is not for recruitment, please see r/PythonJobs or the thread in the sidebar for that.

/r/Python
https://redd.it/10fmmy9
Best python tutorials, codecamps, courses for begginers in 2023?

I am extremely interested in learning how to code and get a job in tech. After watching many videos on coding for begginers I have come to the conclusion to start with python as that is what 99% of everyone says to start as a first language. Therefore, I was wondering what the best tutorials, codecamps and courses (preferably free but I am willing to pay if its below £250) there are to learn as fast and efficient as possible as a begginer who has little to no experience coding and wants a job in tech. Also, if people can reccomend any good youtube channels or websites/blogs or email newsletters that would be amazing!

/r/Python
https://redd.it/10f8odt
I made an URL shortener in python

I saw the idea on a list of project and thought it was interesting.

It uses flask to handle the redirects and pickle to save short urls.

Here is the repo.

Interested to see what you think!

/r/Python
https://redd.it/10fhivs
Instagram bot generates images using Stable Diffusion Webui

So I've written an Instagram bot in python that gets a prompt from an Instagram message then responds with the image it generated from that prompt.

If you want to check the bot out, its tag is @lajosabot. I'll probably bring him online sometime soon.

Here is the source code: https://github.com/Krizsan0596/InstaDiffusion

I'm interested to see what you think!

/r/Python
https://redd.it/10fhd44
DocArray v2: Nicely represent multi-modal data in your ML models

Hey y'all!


A while ago we **announced DocArray v2** here on r/Python, a project for representing, sending and storing multi-modal data, and we were super happy about the positive feedback!


Today we're just giving a quick update on the new alpha version that we have released since then.
Then main focus of this release is making DocArray play nice with ML model training and serving.


DocumentArray's now offer a stacked mode, in which all tensors in said array are, well, stacked! This makes it directly usable as a data batch in a PyTorch model:


from docarray import Document, DocumentArray
from docarray.typing import TorchTensor, ImageUrl
from typing import Optional

class MyImage(BaseDocument):
tensor: TorchTensor3, 224, 224
url: ImageUrl
embedding: TorchEmbedding768

doc = MyImage(...)
da = DocumentArrayMyImage.stack()
t = da.tensor # returns a big stacked image tensor (batch)


/r/Python
https://redd.it/10f8bms
I think I found a bug in subprocess and created a test case, whats the best way to let the python development team know?

Subprocess can take in an input stream, except when that input stream is a Spooled Temp file, in which case that fails.


Here's an example:

https://github.com/zackees/python-subprocess-bug-spooled-temp-file


How can I let the pydevs know?

/r/Python
https://redd.it/10fbw6t
CS50 during PhD in Earth Sciences? advices gratefully appreciated :)

Hi everyone!

I'm a geologist (hydrogeologist) who started my PhD in the discipline of earth and environmental sciences in October 2022.

About two months ago, after listening to a webinar on the use of Python in GIS and hydrogeology, I started learning this language out of sheer curiosity - I had never been exposed to programming before really.

A few days ago I managed to finish my first mini-project, if that's what I can call it, which allows me to download multiple sets of data simultaneously from the website of a river monitoring unit, in addition, my program allows me to combine multiple CSV files into one and filter them and present the data in plots much faster than, for example, I would have to do it in Excel. Which is awesome!!!

Long story short, it seems to me that programming can strongly help me during my four years of doctoral studies and expand my CV. One of the main goals of my research is to build an HEC-RAS model that would be used to perform a risk assessment of water intake. As you can probably guess, a very important part of this type of work is the collection and processing of large data

/r/Python
https://redd.it/10fi6wq
Django Querying Mastery: Only in 6 Min Read

Unlock the full potential of your Django databases with this comprehensive guide on how to master the art of querying. From filtering data to fetching it in a specific format, this tutorial covers it all. Dive deep into advanced querying techniques such as using Q objects, annotations, aggregations, exclusions, and sorting. Learn how to perform annotation on filters and aggregation on annotations, as well as filtering on annotations. This guide has been crafted after extensive research on the official documentation, source code, and real-world use cases to bring you the most essential and commonly used queries. Whether you're a beginner or an experienced developer, this tutorial is sure to take your Django querying skills to the next level. Django ORM Examples and Exercises

/r/djangolearning
https://redd.it/10eu0mt
SessionId inside the cookie header slows down request

Hi,
I'm learning how to use django sessions and caching.

I noticed that once I login, a sessionId is included in the cookie header. I'm using the "@authentication_classes" and "@permission_classes" decorators to validate the session.

I'm also using Redis to cache the session, since I dont want to hit the DB everytime. I followed the docs for the django and redis server setup.

Once the user log in, the session is written in the cache. The problem is that, even tho the session is inside the cache, the database is hit with each request and it slows down the response time to around 300ms.

This is the api I'm using for testing. It does nothing, but it takes 300 ms and it does hit the DB each time I call it. I'm using "never_cache" because I dont want the entire response to be cached.

@apiview(["GET"])
@authenticationclasses (SessionAuthentication)
@permissionclasses([IsAuthenticated])
@nevercache
def test(request, username):
return JsonResponse("", safe=False)

this is the request I'm making:

https://preview.redd.it/hs6o0thwlsca1.png?width=1018&format=png&auto=webp&v=enabled&s=b6955519bd8e58e8cbc5fd580ff7c15c877c5a90

If I remove the session autentication decorators, a SessionId is not required anymore to

/r/djangolearning
https://redd.it/10f699i
how to loop through options in a for loop via With and Includes

i am using With and includes

{% with "'apple', 'pear', 'banana'" as fruit %}
{% include 'includes/contact-form/options/fruit.html' %}
{% endwith %}

and in my includes i have

<ul>
{% for item in fruit %}
<li>{{ item }}</li>
{% endfor %}
</ul>

but its printing out each letter, per li tag!i can't do any model/view edits, so it has to be within this 'with' thing!

/r/djangolearning
https://redd.it/10dma61
GPT-4 Will Be 500x Smaller Than People Think - Here Is Why

&#x200B;

Number Of Parameters GPT-3 vs. GPT-4

The rumor mill is buzzing around the release of GPT-4.

People are predicting the model will have 100 trillion parameters. That’s a trillion with a “t”.

The often-used graphic above makes GPT-3 look like a cute little breadcrumb that is about to have a live-ending encounter with a bowling ball.

Sure, OpenAI’s new brainchild will certainly be mind-bending and language models have been getting bigger — fast!

But this time might be different and it makes for a good opportunity to look at the research on scaling large language models (LLMs).

Let’s go!

Training 100 Trillion Parameters

The creation of GPT-3 was a marvelous feat of engineering. The training was done on 1024 GPUs, took 34 days, and cost $4.6M in compute alone [1\].

Training a 100T parameter model on the same data, using 10000 GPUs, would take 53 Years. To avoid overfitting such a huge model the dataset would also need to be much(!) larger.

So, where is this rumor coming from?

The Source Of The Rumor:

It turns out OpenAI itself might be the source of it.

In August 2021 the CEO of Cerebras told wired: “From talking to OpenAI, GPT-4 will be about 100 trillion parameters”.

A the time, that was most likely what they

/r/Python
https://redd.it/10fw3a5