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
is installing jupyterthemes safe?

Hi there,

Just a curiosity - I get extreme strain and headaches from looking at monitors for to long so I installed juptyerthemes to enable darkmode since its not already a thing. Everything I could find didnt give a definite answer as to whether it was malicious or not...

/r/JupyterNotebooks
https://redd.it/xfjkee
Edit DB

Best approach to edit DB in production? For instance in case of a new group of users to register? I usually write a .py file using Alembic, but maybe there is a better approach. Writing raw SQL is not great I think, as I have many columns using SQLAlchemy's "default" param, so they would not be automatically set by raw SQL queries.

/r/flask
https://redd.it/xnkwyz
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/xn81cz
Monday Daily Thread: Project ideas!

Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.

/r/Python
https://redd.it/xo37yn
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/xnpn0j
Where is self.client inherited from?

The [official documentation](https://docs.djangoproject.com/en/4.1/topics/testing/tools/#default-test-client) states:

> Every test case in a django.test.*TestCase instance has access to an instance of a Django test client. This client can be accessed as self.client.

And sure enough, this works. But:

from django.test import TestCase

dir(TestCase)

returns no method called "client".

Where is self.client inherited from?

/r/djangolearning
https://redd.it/xoeqv0
validate value calculated from another field

i need to validate a field in django admin.

the field is calculated based upon a value of another field.

i've tried several solutions but none could work like i intended, for example:

1. i calculated the value before saving and then raise a validation error but i didn't manage to make the error pop inside the form (as a red string like the validator already build inside django)
2. i tried to use a validator already build in but i didn't know how to reference the other field inside the validator. ** this would be the ideal solution since its the cleanest**
3. i tried to manipulate the admin form to validate the value but the value is not yet calculated in there as far as i know. in this attempt i also tried to make the field of interest ( the one that get calculated) as a property using a decorator so it would be calculated before validation

what i am trying to achieve is to create a Trade model where i insert the amount of capital to invest and the risk per share i want to take. the idea come from this blog. basically i'm trying to replicate the functionality of the Money

/r/djangolearning
https://redd.it/xohm8s
How I deploy my bootstrapped Python webapp with 150k monthly users

I am a one-man show building a web-based software product. Some quick facts about my app:

Written in Python Flask
150k visitors per month
15k registered users
3k US$ revenue per month
70 requests per second at peak-time

This is a technical post looking at the infrastructure that runs my app with a focus on how I deploy it.

## Summary

I use 2 VPS (virtual private servers) running on DigitalOcean
The database is Postgres and is fully managed by DigitalOcean
I use a blue-green deployment
Deployment is done via `git` and `ssh`.
No CI/CD
No containers
Absolutely no Kubernetes

I am a strong advocate of using "boring technology". I am also the only developer of the app, which makes many things simpler.

## The application infrastructure

The app is a CRUD monolith that is deployed as one artefact. I use nginx and gunicorn to serve the app.

The app runs on 2 virtual private servers, one of which is the production server, the other of which is the staging server. During deployment, they switch roles. This is a so-called blue-green deployment, more on that later.

I'm using a DigitalOcean droplet with 8 shared CPUs, 16GB of memory and 80 GB of storage for each server.

/r/Python
https://redd.it/xobba8
Does some CSS work differently in Django?

I have this CSS. It works fine when I use it for a regular site from just plain HTML and CSS. When I use this with my Django template it acts differently. What I expect to happen is the navigation bar will be flush with the top of the screen. This happens with the plain HTML site. In Django, however there is a gap at the top where you can see the body of the page.

`* {`

`-webkit-box-sizing: border-box;`

`-moz-box-sizing: border-box;`

`box-sizing: border-box;`

`}`

​

`body {`

`margin-top: 90px;`

`background-color: lightgray;`

`}`

​

`.navi {`

`position: fixed;`

`height: 45px;`

`top: 0;`

`right: 0;`

`left: 0;`

`background-color: black;`

`color: white;`

`padding: 5px`

`}`

​

`.navi-link {`

`color: white;`

`text-decoration: none;`

`padding: 5px;`

`}`

Edit: Here is the HTML

In Django:

`{% load static %}`


`<!DOCTYPE html>`
`<html lang="en">`
`<head>`
`<meta charset="UTF-8">`
`<link rel="stylesheet" href="{% static 'css/style.css' %}">`
`</head>`
`<body>`
`<header>`
`{% include 'navi.html' %}`
`</header>`
`{% block content %}`


`{% endblock %}`


`</body>`
`</html>`

Regular HTML:

`<!DOCTYPE html>`

`<html lange='en'>`

`<head>`

`<meta charset='UTF-8'>`

`<title>Practice CSS</title>`

`<link rel='stylesheet' href='style.css'>`

`</head>`

`<body>`

`<header class='navi'>`



`<a class='navi-link' href='index.html'>Home</a>`

&#x200B;

`</header>`



`<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

/r/djangolearning
https://redd.it/xox2gy
Tuesday Daily Thread: Advanced questions

Have some burning questions on advanced Python topics? Use this thread to ask more advanced questions related to Python.

If your question is a beginner question we hold a beginner Daily Thread tomorrow (Wednesday) where you can ask any question! We may remove questions here and ask you to resubmit tomorrow.

This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.

/r/Python
https://redd.it/xp0c2v
How to modify POST data before it gets validated without throwing a ValueError exception?

I am trying to convert a date that is created by a frontend datetime library to a iso formatted date.

I do this using python's strptime function, which throws an exception if it can't format the date. I do this in my view and Django shows an exception page in that case, but I want Django to throw a normal ValidationError that can be seen in the frontend.

I tried writing a clean_date() function in my form to modify the date but Django's DateTimeField validator runs before clean_date() and so my code is never run.

/r/django
https://redd.it/xpn1bw
Videos in HTML

Hello,

I am working on a project, and I am trying to get a video playing in the DOM but I am having lots of trouble.

I have done a lot of researching but I cannot find the actual problem. The videos I am trying to play are MP4 but I can convert them if needed.

Everything works fine in non-Chromium based browsers like Safari or FireFox. But in Chromium browsers, the video loads fine but anytime seeking is requested, the video restarts.

I have tried with the video controls in the browser as well as programmatically with JavaScript, both just jump to the beginning of the video.

Also, I do not know if this is supposed to happen, but in all browsers it makes three total requests.

(Copied from Google Chrome Dev Tools as fetch):


1st:

GET /media/inspection_media/test.mp4 HTTP/1.1
Accept: */*
Accept-Encoding: identity;q=1, *;q=0
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Cookie: csrftoken=token; sessionid=id
Host: localhost:8000
Range: bytes=0-
Referer: http://localhost:8000/home/%5Eredirected/(%3FP1%5Cd+)/$
Sec-Fetch-Dest: video
Sec-Fetch-Mode: no-cors
Sec-Fetch-Site: same-origin
User-Agent:

/r/django
https://redd.it/xppsmw
Running Python Script Online

Hey Guys

I made a script and its running perfectly. The script logs in to a webpage and checks something after that it sends me an email. I used selenium for it.

Now is my question if there is a service where I can run this script like once a hour. Whats the best service to do this?

My first guess was to just use the win10 taskscheduler but it was not reliable.

/r/Python
https://redd.it/xpoxrh
How to use remote jupyter kernel with vscode in my local pc?

Hi, I want to use a python environment in remote server together vscode jupyter notebook extension in my local pc. I used remote extension in vscode and added remote jupyter server but I don't want to use the file in remote machine. I wanna use the files in my local pc with remote jupyter kernel. So, I just wanna use remote computing with jupyter kernel and store my data in my local pc. Is it possible?

https://preview.redd.it/llcfupk8d0o91.png?width=631&format=png&auto=webp&s=e15858ed524d133daf17c24c686af83ec631c4e0

/r/JupyterNotebooks
https://redd.it/xeu1pl
How to use SageMath use Jupyter

I was wondering how to use sagemath with jupyter. I am not experienced with jupyter or sagemath though I was able to install jupyter and get it running. However I am not sure if I have installed sagemath correctly and wasn’t sure how to setup it up so my notebooks can use sagemath. Any help or resources are greatly appreciated thanks!

/r/JupyterNotebooks
https://redd.it/xejik2
D Any Python Code available for Visualizing Named-Entities and Relations?

I'm looking to visualize named-entities and relations over a very large set of documents and saving this in some external document (like a PDF or HTML file). Specifically, given that I have the document locations corresponding to the entities and relations, I am looking for something to label every entity with a specific color corresponding to its entity type and colored arrows corresponding to relation type between related entities. Is there any python code available to do this?

I tried generating a PDF using PyFPDF but it won't easily let me color individual words. For now, I am giving up on PyFPDF and trying to use python to generate HTML and CSS.


UPDATE: Turns out I can use PyFPDF to color individual words (using the write function rather than the cell/multicell functions). However, still trying to figure out how to draw arrows between words. Any suggestions for libraries that can do this easily would be appreciated!

/r/MachineLearning
https://redd.it/xq61zi
Is there a way to use Store Magic across 2 Jupyter notebooks (one running Python & one running R)?

I've used the store magic for 2 python notebooks and that worked well. Just curious if there is a way to share data between a R notebook and a Python notebook.

Thanks in advance.

/r/JupyterNotebooks
https://redd.it/x578xu
I built a platform for helping Django developer to find a new job.. and it's work pretty well !

Hey r/Django :),

I'm a freelance Django dev and I'm making some side projects (Big fan of the indie hacking movement)

My last one is a platform for helping Django developers to find a new job or a new freelance contract (https://www.djangotop.com).It's 100% free. I put it online 1 month ago and I already have 70 devs that are signed up :D (and 2 found a job !)

Do not hesitate to give feedback and if you are interested, create your profile ! It helps me to be able to bring back more traffic from companies interested in Django developers !

/r/django
https://redd.it/xq7jlx