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
SSL certificate

My django app on an EC2 instance works fine with http://IP.address. I also used Route 53 to link up with a domain and now http://domain.com works

But why does https://domain.com not work? The domain had been previously linked with an SSL certificate. HTTPS is allowed on my EC2s security group. Do I need another SSL ?

/r/django
https://redd.it/y6xanb
PYTHON CHARTS: the Python data visualization site with more than 500 different charts with reproducible code and color tools

Link: https://python-charts.com/
Link (spanish version): https://python-charts.com/es/


This site provides tutorials divided into chart types and graphic libraries:

https://preview.redd.it/6yk59rxp8eu91.png?width=748&format=png&auto=webp&s=0581694dcacd8d7e9e7909b2c13dd0b76f7bd64c

​

The graphs can be filtered based on the library or chart type:

​

https://preview.redd.it/dyo2btgz8eu91.png?width=1058&format=png&auto=webp&s=a22b43408411950c2351367a96e871279f368acc

​

Each post contains detailed instructions about how to create and customize each chart. All the examples provide reproducible code and can be copied with a single click:

https://preview.redd.it/d681tn319eu91.png?width=1553&format=png&auto=webp&s=05fd21d7a896082753c55cec461df67460ee07fb

​

The site also provides a color tool which allows copying the named, colors or its HEX reference:


​

https://preview.redd.it/ptwelwb99eu91.png?width=1299&format=png&auto=webp&s=54bc17e012790a55d62604f1d8a5fcb6565ab381


There is also a quick search feature which allows looking for charts:


​

https://preview.redd.it/gpoz93wd9eu91.png?width=1013&format=png&auto=webp&s=fa3af72c6b2ef43444278e74032a0ebae3d9c143


Hope you like it!

/r/Python
https://redd.it/y6fumv
Why is X not defined?

import numpy as np

​

a = float(input("oppgi nedre grense, a, på intervallet:"))

b = float(input("oppgi øvre grense, b, på intervallet"))

n = int(input("oppgi ønsket antall partisjoner (delintervaller) (Husk partall):"))

ant_des = int(input("oppgi ønsket antall desimalet i svaret:"))

​

h = (b-a)/n

​

\#simpsons metode

x_vektor = np.linspace (a,b,n+1)

y_vektor = 1/ 1 + x**6



​

vekt = np.ones(len(x_vektor))

for i in range (1,n):

if i % 2 == 0:

vekt [i\] = 2

else:

vekt [i\] = 4

​

print ("Komponenten vektes etter flg system", vekt)

​

skalarprodukt = y_vektor * vekt

Sum= skalarprodukt * h/3

print (round(sum,ant_des))

​

I dont understand why this code dosent work. its a code thats suppose to give you the numbers to simpsons methode in math

/r/JupyterNotebooks
https://redd.it/y77txv
Real life examples of complex applications

Are there some good examples of real applications (not hello world todo/blog post or tutorials) of Flask applications, from where a new flask user could learn best practices from?

Flask doesn't force any design patterns or specific ways to do anything on me, and that leaves me wondering about what are the best ways to do something. How do I split up the routes file from all-routes-in-a-file.py to something more manageable, how do I validate input requests coming from a JS front-end, what are the best practices for doing thing X and Y, that I haven't even thought about yet.

Background information: I am writing a back-end api for a Vue frontend, there are no templates in the flask app, I am using JWT for authentication already. I think I don't need blueprints, because I don't have any templates to separate from the other things. I just don't want to bunch all my routes together in a huge file, like.. all the examples on the internet do.

I have found some open-source flask examples, but they seemed to be doing something weird, or.. were really outdated.

Or should I just write my back-end in Java and Spring, since that is used at work,

/r/flask
https://redd.it/y7hkgo
Can i host my django app under 10$?

So i am trying to create a project for my portfolio and it will be a simple blog application and i want to know if i will be able to host it under 10$ a month if only me and maybe 5-10 of my friends will visit it(not daily maybe once or twice a week).

English is not my first language so sorry if i did not express my thoughts clearly.

/r/django
https://redd.it/y7lmtd
Wednesday Daily Thread: Beginner questions

New to Python and have questions? Use this thread to ask anything about Python, there are no bad questions!

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/y7n3gz
Django + async: delete from DB

Django version 4.1.2

I just used the following code snippet:
r = await mymodel.objects.aget(some_name=myname)
await r.adelete()

This fails with: "AttributeError: 'mymodel' object has no attribute 'adelete'

But this does work though:

r = await mymodel.objects.aget(some_name=myname)
await sync_to_async(r.delete)()


Any fix for this?

/r/django
https://redd.it/y7w5dm
Call for questions for Guido van Rossum from Lex Fridman

Hi, my name is Lex Fridman. I host a podcast and I've previously interviewed Guido van Rossum (4 years ago). I'm talking to him again soon and would like to hear if you have questions/topic suggestions, including technical and philosophical ones, on Python or programming in general.

/r/Python
https://redd.it/y7q4gv
django creating new record when update existing record

this is a strange issue, and cant trace it.whenver i am updating a field in my existing record django creats another new record with updated value. what could be the reason?below is my edit view

@cachecontrol(nocache=True, mustrevalidate=True,nostore=True)
@loginrequired(loginurl="login")
def edittonerdetailssave(request):
if request.method == "POST":
tonerdetailsid = request.POST.get("tonerdetailsid")

employeename = request.POST.get("employeename")
employeedesignation = request.POST.get("employeedesignation")

status = request.POST.get("status")

# issuedtoid = request.POST.get("issuedto")
# issued
to = Prosecutions.objects.get(id=issuedtoid)

tonermodelid = request.POST.get("tonermodel")
toner
model = Toners.objects.get(id=tonermodelid)



/r/django
https://redd.it/y86jjd
Choosing between options for presenting Plotly figures on a website (Python/Jupyter)

I'm looking to share some of my charts (Plotly) (on a Github webpage first and later on, on a personal website - not the notebooks, but the charts by themselves. I have spent a lot of time and found it surprisingly difficult to get started, and would very much like some input.

The options that I see would be the most relevant are:

1. Export from Jupyter Notebooks/labs to HTML - limited interactivity?
2. Dash
3. Panel/HvPlot

I have started out following a YouTube tutorial on option 3. This didn't present a way to actually show the plots on a website. For this option, the order of operations seems to be:

Python/Pandas -> Make plotly figures and interactive dataframes -> use HvPlot -> Use Panel (or similar) -> host this in Heroku/MyBinder/similar.

Am I on the right track here?

/r/JupyterNotebooks
https://redd.it/vlohr8
django creating new record when update existing record

this is a strange issue, and cant trace it.whenver i am updating a field in my existing record django creats another new record with updated value. what could be the reason?below is my edit view

@cachecontrol(nocache=True, mustrevalidate=True,nostore=True)
@loginrequired(loginurl="login")
def edittonerdetailssave(request):
if request.method == "POST":
tonerdetailsid = request.POST.get("tonerdetailsid")

employeename = request.POST.get("employeename")
employeedesignation = request.POST.get("employeedesignation")

status = request.POST.get("status")

# issuedtoid = request.POST.get("issuedto")
# issued
to = Prosecutions.objects.get(id=issuedtoid)

tonermodelid = request.POST.get("tonermodel")
toner
model = Toners.objects.get(id=tonermodelid)


/r/djangolearning
https://redd.it/y86gkt
KeyError when the key exists

*Solved:*

Thanks u/vikingvynotking. The `format()` method required explicitly setting the key/value pair as opposed to just the positional argument. Changing it to:

`success_message = REGISTRATION_SUCESS.format(username=request.POST['username'])`

fixed the `KeyError`. However the message still isn't being displayed but I've yet to work on that :)

\--------------------------------------------------

*Goal:*

After a user registers via a form, have CreateView provide a message welcoming that user, using the username supplied with the POST data.

*Method:*

Override the CreateView's `post()` method to access the `request` object and its `POST` dict to retrieve the provided username.

*Problem:*

**Django/Python throws a** `KeyError` **suggesting that the key doesn't exist.** Looking at the values available to the method, the key does, in fact, appear to exist.

*Possible Solution:*

Could this have something to do with CBVs being instantiated when Django first runs and therefore any POST data doesn't yet exist? I had a similar problem with trying to use `reverse()` for success URLs, but that was an easy switch to `reverse_lazy()`.

*Traceback:*

ERROR:django.request:Internal Server Error: /accounts/register/
Traceback (most recent call last):
File "/home/dedolence/Documents/projects/mocktions2/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/home/dedolence/Documents/projects/mocktions2/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response


/r/djangolearning
https://redd.it/y8abcq
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/y8iisy
If you could rename 1 component of the Python language, which one would it be?

We all know that naming things is notoriously hard and it is easy to judge in hindsight.

That being said, if you could change the name of one Python function/method/keyword etc., which one would it be? Can you suggest a more intuitive name?
It can be part of the core language, the standard library, or some third-party package.

Recently, I watched a talk by Raymond Hettinger where he would rename the else clause in Python for-loops to nobreak from today's perspective.

Personally, I have a hard time remembering what dict.setdefault() does. For some reason, I immediately connect the word default to initializing some kind of object rather than updating some value.

Excited to hear your picks!

/r/Python
https://redd.it/y887d1
Honest question: Why must "self" always be passed in as parameter, why wasn't it made a built-in?

In most of my conversations with fellow Rubyists on language wars, this point always comes up. For one, when you always precede the "self" parameter (like in below code), there is an ambiguity. For example, you actually have 3 parameters but when you call it, it only has 2. Another problem is the obvious redundancy and repetition of the "self" keyword here. My question is:

1. Why was it so important for designers of the language to make declaration of self parameter so explicit? Having a built-in self object for the class instance like Java's this or PHP's $this should have been a no brainer.
2. Going forward, are there any plans to fix this in a future Python version by making self a built-in?


class Animal:

# instance attributes
def init(self, name, family):
self.name = name
self.family = family

# instance method
def sing(self, song):
return "{} sings {}".format(self.name, song)

def dance(self):
return "{} is now dancing".format(self.name)

/r/Python
https://redd.it/y8ofb6
count

i am counting certain toners in stock with the below query.it works fine until the last item .but after the last item the remining_qty field doesn't update to zero.as you can see i am updating my remaininy_qty field based on the count of tonerdetails in stock.

def calcremainingqty():
for toner in Toners.objects.filter(tonerdetailsstatus="In-Stock").annotate(tonerdetailscount=Count('tonerdetails')):
toner.remaining
qty = toner.tonerdetailscount
toner.save(updatefields='remaining_qty')

below is my toner and toner details models.

class Toners(models.Model):

tonermodel = models.CharField(maxlength=10,null=True)
tonerprinter = models.ForeignKey(Items,ondelete=models.CASCADE)
totalqty = models.PositiveIntegerField(default=0,null=True)
remaining
qty = models.PositiveIntegerField(default=0,null=True)
created=models.DateTimeField(default=datetime.now())
objects = models.Manager()

class TonerDetails(models.Model):
STATUS =
('In-Stock', 'In-Stock'),
('Out-of-Stock', 'Out-of-Stock'),



/r/django
https://redd.it/y8sh6f
All Data Structures and Algorithms Concepts and Solutions Stored in a Structured Manner 🎯🔥

Repository Link: **https://github.com/SamirPaul1/DSAlgo**

In this repository, I have stored solutions to various problems and concepts of Data Structures and Algorithms in Python3 in a structured manner.

Topics Covered:

[Dynamic Programming](https://github.com/SamirPaul1/DSAlgo/tree/main/02_Dynamic-Programming)
**Sorting Algorithms**
[LinkedList](https://github.com/SamirPaul1/DSAlgo/tree/main/04_LinkedList)
**Object-Oriented Programming**
[Binary Trees](https://github.com/SamirPaul1/DSAlgo/tree/main/06_Binary-Trees)
**Graph Algorithms**
[Heap](https://github.com/SamirPaul1/DSAlgo/tree/main/08_Heap)
**Matrix**
[Trie](https://github.com/SamirPaul1/DSAlgo/tree/main/10_Trie)
**Binary Search**
[Backtracking](https://github.com/SamirPaul1/DSAlgo/tree/main/12_Backtracking)
**Stack**
[Queue](https://github.com/SamirPaul1/DSAlgo/tree/main/14_Queue)
**Greedy**
[String](https://github.com/SamirPaul1/DSAlgo/tree/main/16_String)
**Bit Manipulation**
[Array](https://github.com/SamirPaul1/DSAlgo/tree/main/18_Array)
**HashMap**
[DFS BFS](https://github.com/SamirPaul1/DSAlgo/tree/main/20_DFS-BFS)
**Two Pointers**
[Math](https://github.com/SamirPaul1/DSAlgo/tree/main/22_Math)
**Recursion**

In various folders of the above topics, you can find questions and concepts related to that topic.

In the [Dynamic Programming](https://github.com/SamirPaul1/DSAlgo/tree/main/02_Dynamic-Programming) section, you can find all the questions covered and not covered in [Aditya Verma's](https://www.youtube.com/c/AdityaVermaTheProgrammingLord) [dynamic programming playlist](https://youtube.com/playlist?list=PL_z_8CaSLPWekqhdCPmFohncHwz8TY2Go) folder-wise with my [handwritten notes](https://raw.githubusercontent.com/SamirPaul1/DSAlgo/main/02_Dynamic-Programming/Dynamic-Programming-NOTE.pdf).✍️
If you are preparing for an interview from **Striver’s SDE Sheet** then the **30-Days-SDE-Sheet-Practice** will be helpful to you. Here I have stored solutions to questions of each day with short notes to each solution, as short notes about the approach are very helpful during revision.🎯
In the [Questions-Sheet](https://github.com/SamirPaul1/DSAlgo/tree/main/Questions-Sheet) directory, you can find questions asked by top product-based companies.
There is a collection of books and pdfs on various important computer science fundamentals in the **BOOKS-and-PDFs** directory.📚

​

I am continuously trying to improve this repository by adding new questions and concepts related to the respective topic. Please feel free to

/r/Python
https://redd.it/y8pqyi