pythondaily | Образование

Telegram-канал pythondaily - Python Daily

1102

Daily Python News Question, Tips and Tricks, Best Practices on Python Programming Language Find more reddit channels over at @r_channels

Подписаться на канал

Python Daily

Difference between 'polls' and 'polls.apps.PollsConfig'

I am very much new to django. Recently I was reading the tutorial on how to create 'polls' app . In that tutorial, it said to include 'polls.apps.PollsConfig' to INSTALLED_APPS . So my question is . In some previous tutorials , the tutor had just included the name 'polls' . So is there any difference??

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

Читать полностью…

Python Daily

Flash not reading .env values on live Ubuntu server

Hi,

Trying to deploy an app on an Ubuntu server, but I'm unable to get flask to read system environment variables. Heres a basic code snippet on my init file:

from flask import Flask, Blueprint
from os import environ

app = Flask(name)

print(environ.get("DBUSER"))

if name == "main":
app.run()

DB\
USER prints None. However, if I manually open up a python shell in this directory, and I print the env value, it works. I am using system environments and not an .env file.

I have also tried loading python_dotenv in my wsgi file. Although I don't even think this is needed since I'm loading system environment variables instead of an .env file.

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/app/")
from dotenv import loaddotenv
load
dotenv()
from app import app as application

​

/r/flask
https://redd.it/yrhpl0

Читать полностью…

Python Daily

Writing to two tables from one flask app

Hello all!

I have a flask app that recieved requests and returns results relatively often with a single table within a DB. I have a second table, unrelated to the first, where I just need to run a while loop endlessly to write and overwrite some values every X amount of time. I've written the script which does the loop and it works fine. The question is can I update a seperate table unrelated to the first, from within that same flask app, or do I need to write and manage another flask server?

Thank you!

/r/flask
https://redd.it/yrdyb1

Читать полностью…

Python Daily

serving videos from backend

Hey guys, I've an app where i want to display videos on the frontend. I've stored the videos as files on the backend but that makes the only way to get them is to download them with every request AFAIK. is there a better approach or should i put them as static files on the frontend ?

/r/flask
https://redd.it/yqpsre

Читать полностью…

Python Daily

PyImageOrganizer: Package to easily sort a photo/video collection

Note: This is for photo collections like family photos etc. This is not intended for a movie (video) collection.

I've created a package to accurately search through a given directory for photos/videos and sort them by year > month > date.

It also sorts all other files as unknown files and places them into a directory as well.

Originally I created this as a simple script to mass sort my wife's massive photo collection. However, decided to code it up into a package and share.

Let me know your thoughts!

Project Page: Link

PyPI Page: Link

You can easily install it with

pip install PyImageOrganizer

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

Читать полностью…

Python Daily

Data analysts: what’re some initial steps you take to get familiar w datasets?

I usually use pandas for shape, describe, unique values each column. Recently been going to seaborn to pairplot.

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

Читать полностью…

Python Daily

I made a program to help with my french

This program gives me a Verb, and a person type (Ex: Him, Her them. etc)

now I don't have to make up any (I am lazy, this is programming)

script for anyone who cares: https://pastebin.com/Dz6sUjLB

https://reddit.com/link/yqzo1h/video/yvtvyznsk0z91/player

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

Читать полностью…

Python Daily

Django templates with DRF and React

I was wondering if it’s possible to use django templates with DRF APIs and React (or any other frontend framework)

I was trying to use the same URL with the same port to support React and django

For example, if I have an URL example.com.
I want to have an URI like example.com/login that uses django templates

At the same time I want to have an API example.com/api/cars that maps to example.com/cars/ in React.

Both React and django should uses the same port 443 to use https and the same URL.

How can I implement something like that? Or that even possible to do?

/r/djangolearning
https://redd.it/yqfsz4

Читать полностью…

Python Daily

Django templates with DRF and React

I was wondering if it’s possible to use django templates with DRF APIs and React (or any other frontend framework)

I was trying to use the same URL with the same port to support React and django

For example, if I have an URL example.com.
I want to have an URI like example.com/login that uses django templates

At the same time I want to have an API example.com/api/cars that maps to example.com/cars/ in React.

Both React and django should uses the same port 443 to use https and the same URL.

How can I implement something like that? Or that even possible to do?

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

Читать полностью…

Python Daily

Got hired @ my dream company Microsoft. Here are the items I used for preparation. Good luck.



Data-structure & Algorithms:

Most asked questions at FAANG companies

neatcode

Behavioral Interview Preparation:

Amazon leadership principles - levels

System Design Interview Preparation:

grokking the system design

system design interview book.pdf)

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

Читать полностью…

Python Daily

Which Django core concepts do you have to be an expert/must know to be come a Django web-dev?

I am 49 year old cook. I have been cooking for about 25 years plus. Also, I have been learning Python, Django, CSS, and JavaScript on and off for about 3.5 - 4 years as a hobby - eventually lead to changing my career. My question is prerequisite for Django, or how in dept do I need to know Django in order to become a Django-Web-dev? Here is my recent project at Heroku. It is not finished 100%. I still have a couple of things to fix. Can you check it out please. Does the project look professionally done or is it good enough to enter web-dev career field? Any help will be greatly appreciated. Thank you very much,

/r/djangolearning
https://redd.it/ypw4qx

Читать полностью…

Python Daily

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/yq2tmr

Читать полностью…

Python Daily

How to integrate Telephone Input validation with flask wtform?

How can I integrate telephone number verification using country code with wtform input? Such that you can select your county from a dropdown and the number you input can be verified?

/r/flask
https://redd.it/ypn1aw

Читать полностью…

Python Daily

Pytorch Symbolic: an equivalent of Keras Functional API [Project]

Hello!

I just hit 1.0.0 version of a library I've been developing for the past months as a side project.

# Pytorch Symbolic

A library that aims to provide a concise API for neural network creation in PyTorch. The API and the inner workings are similar to [Keras / TensorFlow2 Functional API](https://www.tensorflow.org/guide/keras/functional) which I always enjoyed using. I decided to go with "Symbolic" in the name instead of "Functional" because I believe it better represents how the library works (also "functional" is kind of taken by `torch.nn.functional`).

I did my best to prepare a useful documentation, so if you are interested, please check it out!
It is filled with examples, best practices, benchmarks, explanations of the inner workings and more.

* [**See Documentation**](https://pytorch-symbolic.readthedocs.io/en/latest/quick_start)
* [See on GitHub](https://github.com/gahaalt/pytorch-symbolic/)
* [See on PyPI](https://pypi.org/project/pytorch-symbolic/)

## Example

This example shows how to create a multiple inputs neural network:
```
from torch import nn
from pytorch_symbolic import Input, SymbolicModel

input1 = Input(shape=(3, 32, 32))
input2 = Input(shape=(3, 32, 32))

output1 = nn.Conv2d(input1.C, 16, 3)(input1)
output2 = nn.Conv2d(input2.C, 16, 3)(input2)
final_output = output1 + output2

model = SymbolicModel(inputs=(input1, input2), outputs=final_output)
model.summary()
```
Keras-like summary is available as well:
```
___________________________________________________________
Layer Output shape Params Parent

/r/MachineLearning
https://redd.it/ypkfwq

Читать полностью…

Python Daily

Is there a way to track which Jupyter Notebooks were being called using run magic?

We have a setup where notebooks call other notebooks using the %run magic command. Is there a way from a given notebook to know which notebooks are calling it?

/r/JupyterNotebooks
https://redd.it/ypskwy

Читать полностью…

Python Daily

Trying to Navigate and understand the Flask Codebase

I am learning web dev in a bottom-up approach from basic socket programming. I consider myself an intermediate programmer. When I navigate inside the flask codebase, I find myself getting lost in deep blue ocean of classes.

This is my understanding of things till now :

A connection between client and server is identified by a unique socket object. In an http protocol, a socket connection is closed after a request-response cycle. For each request that's made to flask app, a socket connection is created and close at end. If that socket object was kept alive than just closing, I feel we now go into world of WebSocket.

In an flask app, app.run start's a while loop. Inside the loop, It's accepting request, parsing the URL and calling the corresponding view to handle that. If I run the flask-server in a multithreaded mode using gunicorn for something, new threads for that view function getting called.

If I defined those view functions with async/await instead, then I would achieve same concurrency by letting other view-functions run while one is waiting on IO.

Problem

But I cannot seem to relate this inside the code. Everything's so deeply nested. Maybe I need to

/r/flask
https://redd.it/yrl5p0

Читать полностью…

Python Daily

Clean Data Easier using Pyjanitor

maxineattobrah/etl-pipeline-with-pyjanitor-7834e6e6f946">maxineattobrah/etl-pipeline-with-pyjanitor-7834e6e6f946" rel="nofollow">https://medium.com/@maxineattobrah/etl-pipeline-with-pyjanitor-7834e6e6f946

/r/pystats
https://redd.it/yrha8h

Читать полностью…

Python Daily

Medical Segmentation The all-in-one 3D medical image segmentation python toolkit. From data annotation to model deployment, you are welcome to try it all!

Hello, everyone!

We have created an open-source all-in-one 3D medical image segmentation toolkit called MedicalSeg. MedicalSeg supports the whole segmentation process including data labeling, data preprocessing, model training, and model deployment. Major features include:

1. Data preprocessing with 30% acceleration using CuPy.
2. High-precision pre-trained models on 5 different organs.
3. High-precision models including nnUnet, TransUnet, UNETR, Vnet, and more models are coming soon!
4. 3D visualization demo based on itkwidgets.
5. AI-assisted 3D medical image annotation platform called EISeg-Med3D: With the 3D segmentation model incorporated into the interactive segmentation algorithm, we managed to improve the annotation efficiency by ten times through AI-assisted click interaction! Combined with the machine learning algorithms and manual annotation toolkit, 100% accuracy is right on your hand. Let alone it is user-friendly and your annotation results and progress are saved automatically.

The following images demonstrate the segmentation result predicted by MedicalSeg:

https://i.redd.it/zk86qbk0z3z91.gif

https://i.redd.it/7mid8m70z3z91.gif

The 3D Medical label toolkit -- EISeg-Med3D

​

​

EISeg-Med3D: https://github.com/PaddlePaddle/PaddleSeg/blob/develop/EISeg/med3d/README\_en.md

MedicalSeg: https://github.com/PaddlePaddle/PaddleSeg/blob/develop/contrib/MedicalSeg/README.md

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

Читать полностью…

Python Daily

SpaceDrones: A simple learning environment for genetic optimization

Hi there,

I created a simple learning environment simulating space drones using PyBox2D for rigid body simulation and PyGame for rendering and visualization. Visualization can be turned off to accelerate the optimization process significantly. The drone's brain is modeled using a neural network implemented with either Pytorch or Numpy. For very small networks, Numpy is significantly faster. The behavior of the drones depends on the specified reward function. Currently, there is a reward for covering as much distance as possible and avoiding collisions with obstacles. The drones' behavior is optimized using a genetic algorithm.

https://preview.redd.it/445b2rn4rxy91.png?width=631&format=png&auto=webp&s=b5b04943a20b9bb6d0cce00fe392cb56f9df5c0b

The example above shows non-interacting drones of one generation during the genetic optimization process. The purple lines are determined by ray casting. They can be used to calculate distances to obstacles. The red lines show the force with which the rocket engines are run. Optionally, drones that come into contact with an obstacle can be disabled.

Github: https://github.com/kaifishr/SpaceDrones

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

Читать полностью…

Python Daily

Baffled by FlaskForm SelectField behavior

I'm scratching my head over some very strange behavior.

# If options in a SelectField come from a variable, the DOM options do not get generated correctly
status_list = [(1, 'Active'), (2, 'Complete'), (3, 'Suspended'), (4, 'Cancelled'), (5, 'Unknown')]
form.status.choices = status_lst
...
tagName: "OPTION"
text: "(1, 'Active')"
textContent: "(1, 'Active')"
title: ""
translate: true
value: "(1, 'Active')"

# If they are directly defined as a list, they get generated correctly
form.status.choices = [(1, 'Active'), (2, 'Complete'), (3, 'Suspended'), (4, 'Cancelled'), (5, 'Unknown')]
...
tagName: "OPTION"
text: "Active"
textContent: "Active"
title: ""
translate: true
value: "1"


Anyone have any idea what's going on?

/r/flask
https://redd.it/yr3fbd

Читать полностью…

Python Daily

Python Asyncio: The Complete Guide
https://superfastpython.com/python-asyncio/

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

Читать полностью…

Python Daily

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/yqzppe

Читать полностью…

Python Daily

[R] Bigscience releases BLOOMZ and mT0 - LLMs that follow multilingual instructions
https://arxiv.org/abs/2211.01786

/r/MachineLearning
https://redd.it/yqf19w

Читать полностью…

Python Daily

Editing form data : fields that a user cannot change - how do YOU handle them?

I'm curious how others approach forms (ModelForms specifically) where there may be data that an end user should not be able to change.

There are options like "show it in a field that is disabled", or "make it a hidden input" and still others suggest not even having the form render it adding it in the form_valid after the submission.

I am curious how others do that.

An example might be an attribute like a 'created_by' field. Or maybe there is a 'related field' that once in place will never change. So there is no need for it to be editable.

So, how do YOU handle it?

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

Читать полностью…

Python Daily

PyPI In a box: Using a Raspberry Pi as a portable PyPI server
https://vuyisile.com/pypi-in-a-box-using-a-raspberry-pi-as-a-portable-pypi-server/

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

Читать полностью…

Python Daily

Weekend scripting adventure - given an IP address find out if it originates from a public cloud provider

As the title says, over the weekend I put together some Python code to lookup an IP address against the IP ranges published by the major cloud providers. Here it is: https://github.com/Twingate-Labs/tg-ip-lookup

There's one script to query AWS, GCP, Azure & Oracle IP ranges and save them to a pickle file and a couple of examples of a CLI for it and a CSV processor.

I did find some prior art here but I wanted something with support for more cloud providers and that used built-in Python modules where possible. The only major dependency here is the geoip2 module that pulls in a fair amount of stuff with it.

Nothing huge but been a while since I wrote something in Python and wanted to share!

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

Читать полностью…

Python Daily

OpenAI Whisper
https://www.youtube.com/watch?v=_xVTgdpokH4

/r/IPython
https://redd.it/yq376r

Читать полностью…

Python Daily

Django Sessions - Explain

Can somebody please explain me the session un django. How it works, how it set & get.

And is it possible to set a session variable in one view and access it in another view?

Please explain it in detail. It would be very helpful.

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

Читать полностью…

Python Daily

A game coded in Python on Steam !

Hello everyone, Im 15, and I make this post because I am happy to tell you that my video game entierly coded with Python is now available on Steam ! I don't know if it is the first one, but you can be sure that there is at least one game coded with Python only, on Steam. Here is the store page, if you want to check that : https://store.steampowered.com/app/2172950/TheCube
Thanks

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

Читать полностью…

Python Daily

N Stability.ai AMA on November 15

Excited to announce an upcoming AMA in /r/MachineLearning with the members of Stability.ai on Nov 15 at 11:00 AM PST. They have been one of the driving forces behind the open-source AI movement, being known for being key in the success of StableDiffusion (https://www.reddit.com/r/StableDiffusion/) and many other disruptive changes to the overall landscape of AI.

​

A thread will be created before the official AMA time for those who won't be able to attend on that day.

/r/MachineLearning
https://redd.it/ypnujk

Читать полностью…
Подписаться на канал